The following two tabs change content below.
Hi, I have written and developed this site to share my experience and ideas with other colleagues. I also started to prepare interview questions and answers for job seekers. I hope it will help you a lot.

Every programming and have an entry point for example Java language has main function to launch java application.
Similar way activity also has own lifecycle which are called activity callback function.

The activity lifecycle/callback methods are:

Called when the activity is first created. This is where you should do all of your normal static set up — create views, bind data to lists, and so on.

Called just before the activity becomes visible to the user.
Followed by onResume() if the activity comes to the foreground, or onStop() if it becomes hidden.

Called after the activity has been stopped, just prior to it being started again.

Called just before the activity starts interacting with the user. At this point the activity is at the top of the activity stack, with user input going to it.

Called when the system is about to start resuming another activity. This method is typically used to commit unsaved changes to persistent data, stop animations and other things that may be consuming CPU, and so on. It should do whatever it does very quickly, because the next activity will not be resumed until it returns.

Called when the activity is no longer visible to the user. This may happen because it is being destroyed, or because another activity (either an existing one or a new one) has been resumed and is covering it.
Followed either by onRestart() if the activity is coming back to interact with the user, or by onDestroy() if this activity is going away.

Called before the activity is destroyed. This is the final call that the activity will receive. It could be called either because the activity is finishing (someone called finish() on it), or because the system is temporarily destroying this instance of the activity to save space.

Lifecycle flow:


Example of activity lifecycle:

package com.kpblog.activity;

import android.os.Bundle;
import android.util.Log;

public class MainActivity extends Activity {

    String msg = "Activity Callback : ";

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        Log.d(msg, " onCreate() event");

    /** Called when the activity is about to become visible. */
    protected void onStart() {
        Log.d(msg, " onStart() event");

    /** Called when the activity has become visible. */
    protected void onResume() {
        Log.d(msg, " onResume() event");

    /** Called when another activity is taking focus. */
    protected void onPause() {
        Log.d(msg, " onPause() event");

    /** Called when the activity is no longer visible. */
    protected void onStop() {
        Log.d(msg, " onStop() event");

    /** Called just before the activity is destroyed. */
    public void onDestroy() {
        Log.d(msg, " onDestroy() event");


1,760 total views, 1 views today

Leave a Reply

Your email address will not be published. Required fields are marked *