android lifecycle for application developers: guidelines and tips
Android activity lifecycle
-
Upload
soham-patel -
Category
Education
-
view
181 -
download
0
description
Transcript of Android activity lifecycle
Android Activity Lifecycle
Activity
An Activity is an application component that provides a screen with which users can interact in order to do
something, such as dial the phone, take a photo, send an email, or view a map.
Each activity is given a window in which to draw its user interface.
An application usually consists of multiple activities that are loosely bound to each other.
Each time a new activity starts, the previous activity is stopped, but the
system preserves the activity in a stack .
When a new activity starts, it is pushed onto the back stack and takes user
focus.
Activity
Go Phish! 4
Android Activity - >
Activity life cycle - >
Go Phish! 6
Method Description Next
onCreate() Called when the activity is first created. onStart()
onRestart() Called after your activity has been stopped, just prior to it being started again.
Always followed by onStart()
onStart()
onStart() Called when the activity is becoming visible to the user.Followed by onResume() if the activity comes to the
foreground, or onStop() if it becomes hidden.
onResume()or onStop()
onResume() Called when the activity will start interacting with the user.
Always followed by onPause().
onPause()
onPause() Called when the system is about to start resuming a previous activity.
onResume()or
onStop()
onStop() Called when the activity is no longer visible to the user.Followed by either onRestart() if this activity is coming
back to interact with the user, or onDestroy() if this activity is going away.
onRestart()or
onDestroy()
onDestroy() The final call you receive before your activity is destroyed.
nothing
Example: When the Activity first time loads the events are called as below:
onCreate() onStart() onResume()
When you click on Phone button the Activity goes to the background and the below events are called:
onPause() onStop()Exit the phone dialer and the below events will be called:
onRestart() onStart() onResume()
When you click the back button OR try to finish() the activity the events are called as below:onPause() onStop() onDestroy()
Activity Stack
If an activity in the foreground of the screen (at the top of the stack),
it is active or running.
If an activity is completely obscured by another activity, it is stopped.
If an activity has lost focus, it is paused.
If an activity is paused or stopped, the system can drop the activity
from memory by either asking it to finish, or simply killing its process.
• Activities in the system are managed as an activity stack. An activity has essentially four states: