Whenever you undertake the process of developing Android Applications, the activity lifecycle definitely serves as the fundamental foundation stone for moving ahead towards this approach.

The well-known lifecycle of an Android activity covers many stages in between its starting and finishing line, which further needs to be explained as lifecycle for an activity in Android Application.

An Activity is a single screen in Android.
It is like a window in a desktop app, or a Frame in a Java program.

It’s important to understand that an Activity has a lifecycle: that is to say that it can be in one of several different states, depending on what is happening with the app and with the user interaction.

Source- Official android website

Let’s take an example, while playing games or watching videos in a mobile phone if we get a call or message then have you ever noticed what will happen to the playing video once you complete your call. Yes, you will see that your video is stopped and again it starts from where you are playing.

It means an activity is started (playing a video) and once your process is stopped or interrupted by anything then the activity will automatically stop.

Life Cycle Methods and Callbacks

In general, activity lifecycle has seven callback methods:

  1. onCreate()
  2. onStart()
  3. onResume()
  4. onPause()
  5. onStop()
  6. onRestart()
  7. onDestroy()

onCreate(): You must implement this callback, to perform basic application startup logic that will happen only once in the whole lifecycle of the activity.

onStart(): The system invokes this callback when the activity enters the started state. Once an activity comes to start method we will see the main screen of the application.

onResume(): When the activity enters into this state the activity stays until the user interacts with any activity such as selecting, clicking on any options for another activity.

onPause(): When the user is moving from one activity to another activity the current activity gets paused. In most cases, on pause() method called by the system when user press Home button (center button on the device). One can use the onPause() method to release the system resources, such as broadcast receivers, or any resource that affect the battery life while your activity is paused

onStop(): This callback is called when the activity is no longer visible to the user, it has entered the stopped state.

onRestart(): It is called when the activity is being restarted, as when the activity is returning to the foreground. It is always followed by onStart() method.   

onDestroy(): It is called before the activity is destroyed. This is the final call that the activity receives. It may also call when a screen orientation change occurs, and then immediately call onCreate() to recreate the activity. The onDestroy() callback releases all resources that have not yet been released by earlier callbacks.


That’s all I have and thanks a lot for reading. Please let me know if any corrections/suggestions. Please do share and comments if you like the post. Thanks in advance… 😉

Thanks Shubham Pathak for helping us to grow day by day. He is passionate to develop the different apps and loves to solve challenging problem in Android.

Categories: Miscellaneous

0 Comments

Leave a Reply

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

Insert math as
Block
Inline
Additional settings
Formula color
Text color
#333333
Type math using LaTeX
Preview
\({}\)
Nothing to preview
Insert