Activity Lifecycle & Callbacks
Activity Lifecycle & Callbacks
o Activity Lifecycle
Contents o Activity Lifecycle Callbacks
Activity Lifecycle
1. If the user files the form and suddenly rotate the screen so all filled data will be lost,
It’s not good.
2. Android limited resources can crash your app if you didn’t release on time
3. Losing the user’s progress if they leave your app and return to it at a later time.
Activity States and Callbacks
● The system calls this method as the first indication that the user is
leaving your activity (though it does not always mean the activity is being
destroyed); it indicates that the activity is no longer in the foreground
(though it may still be visible if the user is in multi-window mode).
● Called when system is about to resume a previous activity
● The activity is partly visible but user is leaving the activity
● Typically used to commit unsaved changes to persistent data, stop
animations and anything that consumes resources
● Implementations must be fast because the next activity is not resumed
until this method returns
● Followed by either onResume() if the activity returns back to the front, or
onStop() if it becomes invisible to the user
onStop() → Stopped
onSaveInstanceState(Bundle onRestoreInstanceState(Bundle
outstate) savedInstanceState)
As your activity begins to stop, the When your activity is recreated after it was
system calls the method previously destroyed, you can recover your
saved instance state from the Bundle that
onSaveInstanceState() so your
the system passes to your activity. Both the
activity can save state information
onCreate() and onRestoreInstanceState()
to an instance state bundle
callback methods receive the same Bundle
that contains the instance state
information.
Lifecycle Practical Situation