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!



As an Amazon Associate I earn from qualifying purchases.

My favorite quotations..


“A man should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects.”  by Robert A. Heinlein

"We are but habits and memories we chose to carry along." ~ Uki D. Lucas


Popular Recent Articles