Monday, January 23, 2017


onCreate():

  • 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, an d so on.
  • Always followed by onStart()

onRestart():

  • Called after the activity has been stopped, just prior to it bein g started again. 
  • Always followed by onStart()

onStart():

  • 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.

onResume():

  •  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. 
  • Always followed by onPause().

Activity Running:

  • It is active or running when it is in the foreground of the screen (at the top of the activity stack for the current task). 
  • This is the activity that is the focus for the user's actions.

onPause():

  •  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. 
  • Followed either by onResume() if the activity returns back t o the front, or by onStop() if it becomes invisible to the user. The activity in this state is killable by the system.

onStop():

  • 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. 
  • The activity in this state is killable by the system.

onDestroy():

  • 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 co ming back to interact with the user, or by onDest roy() if this activity is going away. 
  • The activity in this state is killable by the system.

Life Cycle Functions:

 @Override
    protected void onStart() {
        super.onStart();
        Log.i(TAG, "onStart");
    }


    @Override
    protected void onResume() {
        super.onResume();
        Log.i(TAG, "onResume");
    }


    @Override
    protected void onPause() {
        super.onPause();
        Log.i(TAG, "onPause");
    }


    @Override
    protected void onStop() {
        super.onStop();
        Log.i(TAG, "onStop");
    }


    @Override
    protected void onRestart() {
        super.onRestart();
        Log.i(TAG, "onRestart");
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.i(TAG, "onDestroy");
    }


    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        Log.i(TAG, "onSaveInstanceState");
    }


    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        Log.i(TAG, "onRestoreInstanceState");
    }