Lec 9
Lec 9
3
Android Activity Lifecycle Methods
Method Description Kill After Next
This is called on initial creation of the activity. It is responsible for
onCreate() constructing views, binding data to controls, and managing or restoring No onStart()
state from its given bundle.
onStart() This method is called immediately before the activity shows onscreen. No onResume()
The onResume() method fires when the activity has been created, started,
onResume() and is ready to receive user input. The activity will start interacting with No onPause()
the user after this method completes.
This method is triggered whenever the activity is visible but not
onStop()
interactive. It can be called when the system prepares to transition to
onPause() Yes Or
another activity, or it can be called while the current activity is interrupted
onResume()
and sent to the background (ex. popup is displayed).
onRestart()
onStop() This method is called when the activity is not visible. Yes Or
onDestroy()
This method is invoked after the activity has been stopped, right before
onRestart() starting up again. This happens in cases such as resuming after a phone call No onStart()
or bringing the app back to the foreground.
The method is called before the activity is destroyed. It is usually the result
onDestroy() of an explicit call to finish() from within the activity, or when the Back Yes N/A
button is pressed. This method is called at most once for the activity.
4
5
Cases for Activity Lifecycle
When Next Activity is called from Main Activity
D/MainActivity: calling Next Activity
D/MainActivity: calling onPause from MainActivity
D/NextActivity: calling onCreate from Next Activity
D/NextActivity: calling onStart from Next Activity
D/NextActivity: calling onResume from Next Activity
D/MainActivity: calling onStop from MainActivity
When Returning back to the Main Activity from Next Activity using back button
D/NextActivity: calling onPause from Next Activity
D/MainActivity: calling onRestart from MainActivity
D/MainActivity: calling onStart from MainActivity
D/MainActivity: calling onResume from MainActivity
D/NextActivity: calling onStop from Next Activity
D/NextActivity: calling onDestroy from Next Activity