OnPause(), OnResume() and OnDestroy

android, optimization

Solution

Better to an base activity which contains your code for override methods and then you can extend it your activities instead of activity.

So all the activities which extend baseactivity will be reflected with three methods.

public class BaseActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
    }
   @Override
protected void onPause(){
    super.onPause();

}
@Override
protected void onResume(){
    super.onResume();

}
@Override
protected void onDestroy(){
    super.onDestroy();

}

}

Note what task you want to perform in the above three method? are they same in all activiies then only use the above.

Problem

I have developed a small app which uses several different classes to allow the user to add,remove and view certain data. I use an arrayList to store entries and this has its own class which has methods linked to the array so i can access the array from all of my classes. I want to introduce the above methods to optimise my code and was wondering if I could stick them in one class hopefully the same application class I have my array in and there just define them where they will be getting used, this will save me having to write the same piece of code in several classes, is this possible? Thanks

Original source