Application ComponentsCOMPONENT COMPONENT COMPONENT COMPONENT APPLICATION PROCESS Android is multi-user OS, each application has it’s own user ID because of security reasons.. Android Pr
Trang 1D
PROCESS MANAGEMENT
BY
HOANG VAN KIEN
HOANG HUY KHANH
PHUNG DUC LUAN
Trang 2APPLICATION FUNDAMENTALS
PROCESS LIFE CYCLE
Trang 3Application Components
COMPONENT COMPONENT COMPONENT COMPONENT
APPLICATION
PROCESS
Android is multi-user OS, each application
has it’s own user ID
(because of security reasons)
Android is multi-user OS, each application
has it’s own user ID
(because of security reasons)
Each application has it’s own VM(virtual
machine), to provide isolation from other
process
Each application has it’s own VM(virtual
machine), to provide isolation from other
process
Each application has it’s own process
Application is a combination of
components
Application is a combination of
components
Trang 4Application Components
A
Activities
An activity represents a single
screen with a user interface,
in-short Activity performs
action on the screen.
S
Services
A service is a component that
runs in the background to
perform long-running
operations.
B Broadcast ReceiversBroadcast receivers simply
respond to broadcast messages from other applications or from
the system.
C A content provider component Content Providers
supplies data from one application to others on request.
A Other ComponentsThere are additional
components which will be used
in the construction of above mentioned entities.
Trang 5Application Components
First Activity
Click me!
Second Activity
This is second activity
Trang 6YOUR APP
Application Components
Write Email Get Email Address Send Email
Use Email app to write
Use Contacts app to get email address
Use Email app to send
Your app can use another app’s components
Trang 7Activity Stack
New Activity Started Running activity closedBack button pushed or
Activity 1 Activity 2
Last Running Activity
Activity n-1
Activity 3
…
Activity Stack
Previous Activities Removed to free resources
Trang 8Activity Lifecycle
New Activity
Running
Paused
Destroyed Stopped
1 onCreated()
2 onStart()
3 onResume()
onResume() onPause()
3 onResume()
2 onStart()
1 onRestart()
onDestroy()
onStop()
<<kill>>
<<kill>>
1.Active/Running: if the activity is at the
foreground.
2.Paused: if the activity is at the background
and still visible.
3.Stopped: if the activity is not visible and
therefore is hidden or obscured by another
activity.
4.Destroyed: when the activity process is killed
or completed terminated.
4 states of an activity.
Trang 9Activity Lifecycle
New Activity
Running
Paused
Destroyed Stopped
1 onCreated()
2 onStart()
3 onResume()
onResume() onPause()
3 onResume()
2 onStart()
1 onRestart()
onDestroy()
onStop()
<<kill>>
<<kill>>
There are 7 lifecycle processes in an Android
activity They include −
onCreate − It is called when the activity is first
created.
onStart − It is called when the activity starts
and becomes visible to the user.
onResume − It is called when the activity starts
interacting with the user User input takes place
at this stage.
onPause − It is called when the activity runs in
the background but has not yet been killed.
onStop − It is called when the activity is no
longer visible to the user.
onRestart − It is called after the activity has
stopped, before starting again It is normally
called when a user goes back to a previous
activity that had been stopped.
onDestroy − This is the final call before the
activity is removed from the memory.
Trang 10Android Process
For each application android creates a
new process with single thread of
execution(i.e main thread)
For each application android creates a
new process with single thread of
execution(i.e main thread)
By default all the components run in
same thread(main thread)
By default all the components run in
same thread(main thread)
In low memory situations a process is
decide to kill based upon the number of
inactive components of that process
In low memory situations a process is
decide to kill based upon the number of
inactive components of that process
A process which have more number of
inactive components should be killed
first
A process which have more number of
inactive components should be killed
first
APPLICATION
PROCESS
COMPONENT COMPONENT COMPONENT COMPONENT
THREAD
Trang 11Android Process States
Active Process Visible Process Service Process Background Process Empty Process
Highest
Lowest
1.Active Process
Active (foreground) processes have application
components the user is interacting with:
• Activities in an active state
• Broadcast Receivers executing onReceive
• Services executing onStart, onCreate
• Running Services that have been flagged to run in
the foreground
Process Priority
Trang 12Android Process States
Active Process Visible Process Service Process Background Process Empty Process
Highest
Lowest
2 Visible Process
Visible but inactive processes are those hosting
“visible” Activities This happens when an Activity is
only partially obscured (by a non-full-screen or
transparent Activity)
Process Priority
Trang 13Android Process States
Active Process Visible Process Service Process Background Process Empty Process
Highest
Lowest
3 Service Process
Processes hosting Services that have been started
Because these Services don’t interact directly with
the user, they receive the same priority with visible
process
Process Priority
Trang 14Android Process States
Active Process Visible Process Service Process Background Process Empty Process
Highest
Lowest
4 Background Process
Processes hosting Activities that aren’t visible and
that don’t have any running Services There will
generally be a large number of background processes
that Android will kill using a last-seen-first-killed
pattern in order to obtain resources for foreground
processes
Process Priority
Trang 15Android Process States
Active Process Visible Process Service Process Background Process Empty Process
Highest
Lowest
5 Empty Process
To improve overall system performance, Android will
often retain an application in memory after it has
reached the end of its lifetime Android maintains this
cache to improve the start-up time of applications
when they’re re-launched
These processes are routinely killed, as required
Process Priority