Android coding and reusing of code!

January 11, 2016

Coding is something you need to write to perform the task.

Expert Coding is not only about coding skill, It is something to reuse your repeated code smartly to perform the task within less time:) So be expert, Earn Smart Money.

Start from very basic things like..

Intent in=new Intent(con, MainActivity.class);
startActivity(in);
Create a static class named as StartActivity.java
Write a method there like
public static void toActivity(Context context, Class<?> Destination) {
// TODO Auto-generated method stub
try {
final Intent intent = new Intent(context, Destination);
context.startActivity(intent);
} catch (final Exception e) {
}
}
And call from all other places to navigate screens like
StartActivity.toActivity(con, MainActivity.class);

So after creating the base, you just need to write one line now to open another activity.

If you need to call Activity from 40 classes, you don't need to write 40 lines more to perform same task.

Coding is fun if you know how to do it;)