#Understanding of life cycle of activity is very important for an app developer.
The life cycle of activity says to us how activity created and destroy. After understanding of life cycle of activity, we can use our Function, Object, Class, etc. perfectly. it will manage Function, Class, Etc smoothly.
Let’s Start...
There are many functions below.
- onCreate():- When we start our app onCreate() is called first.
- onStart():- A user can see the UI of activity means that onStart() function has completed.
- onResume():- It is called when the activity starts interacting with the user. This means now a user can edit, add, press, and any type of activity with the UI or activity.
- onPause():- It is invoked when an activity is going into the background but has not yet been killed.
- onStop():- When a user can see the UI and activity goes to in the background means onStop() is going on.
- onRestart():- It is called when the previous activity is called again.
- onDestroy():- It is called when a user kills the activity from the background or pressing the back button.
Understanding of life cycle of activity
Whenever we start or lunch our activity Then onCreate() will call first. Here we can add our view.
A user can see the UI of the app After finishing onStart() function.
When onResume() function will finish then user can do any type of action (Like: Clicking on a button, Edit any thing in edit text field, Etc) .
Whenever user start a new activity the previous activity will go in the onPause() state and onCreate() will start for new activity . If user press on back button and they want to go previous activity then onResume() will call first and user can interact with the previous activity again.
Sometimes user wants to stay the app in background on that situation onPause() will first then onStop() . Then app will run in the background, in this state, our app doesn’t kill. Activity will not visible to the user but it will be running in the background. Sometimes it takes more storage of RAM then Activity is killed by RAM.
Whenever a user restart an activity, first onRestart() will call then onStart() and onResume(). After calling these functions a user can interact with the activity again.
Hope it will help someone…
Thanks:)