View RSS Feed

Android Developer

Android Activity Lifecycle

Rate this Entry
by , 02-11-2012 at 10:00 AM (1884 Views)
All fundamental lifecycle methods of an activity are given in below code skeleton.

Java Code: This is the code to manage lifecycle of an activity
public class ExampleActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // The activity is being created.
    }
    @Override
    protected void onStart() {
        super.onStart();
        // The activity is about to become visible.
    }
    @Override
    protected void onResume() {
        super.onResume();
        // The activity has become visible (it is now "resumed").
    }
    @Override
    protected void onPause() {
        super.onPause();
        // Another activity is taking focus (this activity is about to be "paused").
    }
    @Override
    protected void onStop() {
        super.onStop();
        // The activity is no longer visible (it is now "stopped")
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        // The activity is about to be destroyed.
    }
}
In activity lifecycle, three nested loops can be monitored by implementing these methods.

  • An activity’s entire lifetime is between onCreate() and onDestroy().
  • An activity’s visible lifetime is between onStart() and onStop().
  • An activity’s foreground lifetime is between onResume() and onPause().


Name:  1.JPG
Views: 2228
Size:  38.2 KB

Android Activity Lifecycle

Submit "Android Activity Lifecycle" to Facebook Submit "Android Activity Lifecycle" to Digg Submit "Android Activity Lifecycle" to del.icio.us Submit "Android Activity Lifecycle" to StumbleUpon Submit "Android Activity Lifecycle" to Google

Comments