4h. Android: Activity lifecycle methods

There are few concepts that you will have to get familiar with:

  • activity stack - LIFO (last in, first out )
  • active activity - running activity that is visible and interactive
  • paused activity - running activity that is visible, but obstructed
  • stopped activity - completely obstructed
  • inactivate activity - app has been killed by Android, or the user 





/**
* Activity starts but it is not visible yet, open necessary connections
*/
protected void onCreate(Bundle savedInstanceState) {
super.onStart();
// your code
}
/**
* Activity starts but it is not visible yet, open necessary connections
*/
protected void onStart() {
super.onStart();
// your code
}
/**
* activity was completely hidden by another Activity, or another app, but not killed
* check if you need refresh time-sensitive content (facebook wall update)
*/
protected void onRestart() {
super.onRestart();
// your code
}
/**
* Activity is now visible to the user, resume updating the views
*/
protected void onResume() {
super.onResume();
// your code
}


/** Activity is obstructed, stop updating the views */
protected void onPause() {
super.onPause();
// your code
}
/**
* Activity was obstructed, release resources, or it may get killed
*/
protected void onStop() {
super.onStop();
// your code
}
/**
* Activity is being killed by Android, close network and database connections
*/
protected void onDestroy() {
super.onDestroy();
// your code
}


There is a description available on from Google's Android Developers site:
http://developer.android.com/reference/android/app/Activity.html




It takes time and effort to create tutorials, please support my efforts with a couple-dollar donation, any amount will be greatly appreciated and highly motivating!

No comments:

Post a Comment