9
Android Activit Lifecycle

Android activity lifecycle

Embed Size (px)

DESCRIPTION

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. The window typically fills the screen, but may be smaller than the screen and float on top of other windows. An application usually consists of multiple activities that are loosely bound to each other. Typically, one activity in an application is specified as the "main" activity, which is presented to the user when launching the application for the first time. Each activity can then start another activity in order to perform different actions. 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.

Citation preview

Page 1: Android activity lifecycle

Android Activity Lifecycle

Page 2: 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.

Page 3: Android activity lifecycle

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

Page 4: Android activity lifecycle

Go Phish! 4

Android Activity - >

Page 5: Android activity lifecycle

Activity life cycle - >

Page 6: Android activity lifecycle

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

Page 7: Android activity lifecycle

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()

Page 8: Android activity lifecycle

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:

Page 9: Android activity lifecycle