Lifecycle Flashcards
Explain the android activity lifecycle?
As a user navigates inside & outside of an app, the activities transition through different states.
A number of call-backs are provided to let the app know that there has been a state change.
We can use these call-back methods to manage how the app reacts to the changes in state.
For example, if we have a high data intensive app then we can unsubscribe from any data changes when the app is in the background and re-subscribe when the user resumes the app.
What are some examples of using life cycle callback methods?
- A stock monitoring app can unsubscribe from price changes when the app triggers onPause() and re-subscribe on resume.
- A video streaming app can pause the stream onPause(), resume at same point on resume.
What are the core six callback methods in the activity lifecycle?
- onCreate()
- onStart()
- onResume()
- onPause()
- onStop()
- onDestroy()
In what stage of the lifecycle can the app process be killed?
When the activity goes into the background or is no longer visible (onPause() / onStop()). The app process may then be killed because a higher priority app needs more memory. When the user navigates back to the app, the onCreate() method is executed.
In what situation is the onRestart() callback method called?
When the activity has entered the onStop() state and the user navigates back to the activity. The onStart() method is then called afterwards.