Which is the major issue or difficulty developer face during development
? just ask your self and you will find that answer is Utils function
which we are using in daily basis. We are doing coding whole day most of
the conman things are repeated in all project or module , only some
part of the unique code , view and logic which we added. Developer are
so lazzy to write same code again and again and make create utils class
to make reusable code.
Here i am sharing list of function which we are using in daily basis in android application development which will save your time to find from Google or Stack overflow and write in your utils class or java class. The main objective of this task is Reuse ability of code , Time saving , Easy & Less coding. Let's start.
Here i am sharing list of function which we are using in daily basis in android application development which will save your time to find from Google or Stack overflow and write in your utils class or java class. The main objective of this task is Reuse ability of code , Time saving , Easy & Less coding. Let's start.
You have two ways to use this Utils function :
-
JAVA File
-
Live Template
-
Direct form JAVA file :
You just need to add my created Utils JAVA file in your <package> and access using class object. You can find 120+ utils function in java file but that is not mandatory to add all in your application you can remove list of function which is not useful for your application so that will not save unnecessary code. see below example to see "How to use this class in your activity class?"
0102030405060708091011public
class
MainActivity
extends
Activity {
private
CKAndroidUtils objCKUtils;
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
objCKUtils =
new
CKAndroidUtils(
this
);
if
(objCKUtils.isNetworkAvailable()) {
…..
//Do your task
}
}
public class MainActivity extends Activity { private CKAndroidUtils objCKUtils; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); objCKUtils = new CKAndroidUtils(this); if (objCKUtils.isNetworkAvailable()) { ….. //Do your task } }
Live Template :
Code completion can improve your productivity by reducing how much you have to type, but there are situations when a more powerful tool is needed. Thanks to Android Studio and IntelliJ, live templates make it much easier to focus on just the things you care about. You can read one of the grate article regarding Live Template . You have to create CKAndroidUtils snippet file (XML) which contains your code in XML formate and that will be use to access the function using short cut key : Ctrl + Alt + Shift + J FUNCTION NAME .
How to create your share with others :
Path : File > Settings > Editor > Live Template > .. You can see Add or remove snippet code or template group from “+” or “-“ from right side button.
Now choose Android group or own created template to add snippet code. That will ask you Abbreviation = Function name , Description = What function do, Template text = your code, Type = java , xml ,other. Apply > Ok Done! Now search it using give short cut key and access function any where in your application.
Now you can share added snippet code to other developer and setup same file to get access.
Check out below steps to configure the XML :
Download CKAndroidUtils snippet file
Go to “/.Android Studio/config /templetes folder (by default is hide folder at user /dir)
i.e /home/sotsys073/.AndroidStudio/config/templetesPaste “CKAndroidUtils” file in above /dir.
Restart android studio and check CKAndroidUtils is available in File >> Settings >> Live template >> CKAndroidUtils
Short cut to access function : Ctrl + Alt + Shift + J FUNCTION NAMENow you are able to add function in template and know how to use it . Download CKAndroidUtils.java file and create your snippet or use directly. Start it now!!! Hope this will relay helpful for all of you.
Note : Please add function which you are using in project and not listed in below list so that will be helpful for other
List of Utils Function
Index