Android Activity Life Cycle



In this section I am going to discuss the activity life cycle.So let us first wrap our heads around the concept of activities in Android.

What's an Activity?

Activities are an unusual programming concept specific to Android. In traditional application development there is usually a static main method, which is executed to launch the application. With Android, however, things are different; Android applications can be launched via any registered activity within an application.

What's an Activity's Lifecycle?

The Android activity life-cycle comprises a collection of methods exposed within the Activity class that provide the developer with a resource management framework. This framework allows developers to meet the unique state management requirements of each activity within an application and properly handle resource management.
When an activity’s state is changing, the activity is notified by the OS, which calls specific methods on that activity. The following diagram illustrates these methods in relationship to the Activity Lifecycle:


Start-up Sequence:

  1. 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, etc. This method also provides you with a Bundle containing the activity's previously frozen state, if there was one. Always followed by onStart().
  2. OnStart: Called when the activity is becoming visible to the user. Followed by onResume() if the activity comes to the foreground, or onStop() if it becomes hidden.
  3. OnResume: Called when the activity will start interacting with the user. At this point your activity is at the top of the activity stack, with user input going to it. Always followed by onPause().

Configuration Change Sequence:

  1. OnPauseCalled as part of the activity lifecycle when an activity is going into the background, but has not (yet) been killed. The counterpart to onResume().
  2. 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.
  3. OnDestroyThe 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
  4. OnCreate : (Same as before)
  5. OnSart  : (Same as before)
  6. OnResume : (Same as before)
For more detailed information on activity life-cycle refer the following links:
Or watch these videos on YouTube:
Hope this helped you! Continue reading. 

SHARE

Shobhit Chittora

Hi there, I am Shobhit Chittora. I am a college student and like to develop apps for Android platform.I started this blog to share my experiences with Android development and may be help you guys on the “roadtodroid”.

  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment