In the last article I have discussed about Activity in the Android Development Tutorial Series. Today we will understand the activity lifecycle and the different state of an activity in android that will help you in android application development.
Activity is an application component that provide a single focused screen in Android App with which user can interact in order to do something . Activity is the main component of android app, which is displayed as a single window to the user, handles user events and provides behavior for a screen.
Activity Lifecycle :
The activity life-cycle is the set of states an activity can be in during its entire lifetime, from when it’s created to when it’s destroyed and the system reclaims that activity’s resources. Every screen on Android applications has a lifecycle.
When a user navigates between activities in an app, from when it’s created to when it’s destroyed, they transitions through different states, depending how it interacts with the user.
At every stage in the lifecycle of an activity has a corresponding callback method like onCreate(), onStart(), onPause() etc.
The below Activity life cycle diagram shows the sequence of callback methods :
When an activity changes their state, the associated callback method is called . Overriding a lifecycle callback method allows you to add behavior that occurs when your Activity transitions into that state.
Activity Lifecycle callback methods :
To navigate transitions between stages of the activity lifecycle, the Activity class provides a core set of 7 lifecycle callback methods :
|Callback Methods||Methods Description|
|onCreate||called when activity is first created.|
|onStart||called when activity is becoming visible to the user.|
|onResume||called when activity will start interacting with the user.|
|onPause||called when activity is not visible to the user.|
|onStop||Called when activity is no longer visible to the user.|
|onDestroy||called before the activity is destroyed.|
|onRestart||called after your activity is stopped, prior to start or called when the activity restarts after activity is stopped.|
In our next article we will observe the life cycle calls of the Android system through an example of Android application project.
Thank you 🙂