olajhidey / life-cycle-android

The life cycle callbacks present in android. Just a play around to understand the android life cycle

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

life-cycle-android

The basic android life cycle callbacks. The callbacks override function from the appCompactActivity class

onCreate()

The oncreate callback function is called when our app is instantiated and helps set up our layout view. this callback is the start point of the app you could do alot in the onCreate function. e.g display list of data, start a music or video and many more
      //start the oncreate callback
      @Override
      protected void onCreate(){
      //inherit from super class 
      super.onCreate();

      //Log a message on Create 
      Log.v("onCreate callback", "This is the oncreate callback wow!");
      }    
   

onStart()

The onStart() callback is called when the activity is becoming visible to the user which then change state to the onResume callback
      //start the onstart callback
      @Override
      protected void onStart(){
          //inherit from super class 
          super.onStart();

          //Log a message on Create 
          Log.v("onStart callback", "Yaay! our activity is about to start");
      }  
   

onResume()

The onResume() callback is called when the activity is visible to the user such that the user can actually interact with screen and see components in the app. this callback is always followed by the onPause
    //start the onResume callback
    @Override
    protected void onResume(){
        //inherit from super class 
        super.onResume();

        //Log a message on Create 
        Log.v("onResume callback", "Woaw! I love this image");
    }      
  

onPause()

Called as part of the activity lifecycle when an activity is going into the background, but has not (yet) been killed. The counterpart to onResume(). When activity B is launched in front of activity A, this callback will be invoked on A. B will not be created until A's onPause() returns, so be sure to not do anything lengthy here.
    //start the onPause callback
    @Override
    protected void onPause(){
        //inherit from super class 
        super.onPause();

        //Log a message on Create 
        Log.v("onPause callback", "The activity has been paused");
    }

onStop()

Called when you are no longer visible to the user. You will next receive either onRestart(), onDestroy(), or nothing, depending on later user activity. Note that this method may never be called, in low memory situations where the system does not have enough memory to keep your activity's process running after its onPause() method is called.
    //start the onStop callback
    @Override
    protected void onStop(){
        //inherit from super class 
        super.onStop();

        //Log a message on Create 
        Log.v("onStop callback", "The activity is in the background");
    }

onDestroy()

The final call you receive before your activity is destroyed. This can happen 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. You can distinguish between> these two scenarios with the isFinishing() method.
    //start the onDestroy callback
    @Override
    protected void onDestroy(){
        //inherit from super class 
        super.onDestroy();

        //Log a message on Create 
        Log.v("onDestroy callback", "This activity have been destroyed");
    }

onRestart()

Called after your activity has been stopped, prior to it being started again. Always followed by onStart()
    //start the onRestart callback
    @Override
    protected void onRestart(){
        //inherit from super class 
        super.onRestart();

        //Log a message on Create 
        Log.v("onRestart callback", "This activity is restarting");
    }

About

The life cycle callbacks present in android. Just a play around to understand the android life cycle


Languages

Language:Java 100.0%