DEV Community

Discussion on: Explain Activity Lifecycle Like I'm Five

enzoftware profile image
Enzo Lizama Paredes

An activity is a single screen in android, its like a window in a desktop app. And depends on whats happening with the app and with the user interaction, it can be in one of several states : that the life-cycle.
So, for know what do each method does the best resource is the official docs, but I will try to make a summary as short as possible:

onCreate(): This is called when the activity is initialized, you need implement this method in order to do any initialization specific to your activity.

onStart(): The activity start to be visible for the first time to the user.Once this callback finishes, the onResume() methods will be called.

onResume(): Into this state , it begins interact with the user. The activity continue in this state till something happen to take focus from the app or Activity (such as a incoming call). When this happen the onPause() method is called.

onPause(): This method is used to pause operations that should not happen when the Activity is in paused state. A call to this method indicates that the user is leaving the app.When the user returns to the app, the onResume() method will be called.

onStop(): his method is called when the Activity is no longer visible in the app.In this state, the system either calls the onRestart() to bring back interactivity with Activity. Or it calls the onDestroy() method to destroy the Activity.

OnDestroy(): This gets called before the Activity is destroyed. The system calls this method when a user terminates the Activity, or because the system is temporarily destroying the process that contains the Activity to save space. Be sure to free up any resources your Activity has created in this method, or else your app will have a memory leak.

OnRestart(): This gets called when an Activity restarts after it had been stopped.

Check the classic resources too :

I like this image over the classic one, i believe its more for a #explainlikeimfive topic.

Android LifeCycle

filipjelic profile image
Filip Author • Edited on

If I were five, I would look you like this