You are on page 1of 7

Android

Activity Lifecycle
Component Lifecycle
• Component lifecycle
– From the beginning when Android instantiates a
component to respond to intents through to the end
when the instance is destroyed
– In between, the component may sometimes be active
or inactive
– Activities may be visible to the user or invisible

COMP 107x (Muppala) Android Activity Lifecycle 2


Component Lifecycles
• Activity Lifecycle •Activity in the foreground of the screen

– Three states Resumed (at the top of the activity stack for the
current task)

• Resumed, paused and


stopped
– The system can drop a Paused •Activity has lost focus but is still visible to
the user
paused or stopped activity
from memory either by:
•Activity is completely obscured by
– asking it to finish (calling
its finish() method) Stopped another activity
•It still retains all state and member
information
– simply killing its process.

COMP 107x (Muppala) Android Activity Lifecycle 3


Activity Lifecycle

F
Activity
A r onCreate()
n a onStart()
d m Paused
Resumed
Stopped
Started
onResume() Created
(partially
r e (hidden)
(visible)
visible)
o w onPause()

i o onStop()
d r onRestart()
k
onDestroy()

COMP 107x (Muppala) Android Activity Lifecycle 4


Activity Lifecycle
Activity
launched

onCreate()

onStart() onRestart()
Entire Lifetime

onResume()
Lifetime
Visible

Foreground App process Activity


Lifetime killed Running

onPause()

onStop()

Activity
onDestroy() shut down

COMP 107x (Muppala) Android Activity Lifecycle 5


Coordinating Activities
• When one activity starts another, they both experience lifecycle
transitions
– One pauses and may stop, while the other starts up.
• The order of lifecycle callbacks is well defined, particularly when the two
activities are in the same process. For example if Activity A starts Activity
B:
1. A's onPause() method is called.
2. B's onCreate(), onStart(), and onResume() methods are called in sequence.
3. Then, if A is no longer visible on screen, its onStop() method is called.

COMP 107x (Muppala) Android Activity Lifecycle 6


Chat Client App
• Off to the next app: Chat Client UI
– ListView with Custom Adapter
– Layouts

COMP 107x (Muppala) Android Activity Lifecycle 7

You might also like