Tải bản đầy đủ (.pptx) (16 trang)

Bài tập lớn :quản lý tiến trình android

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (215.37 KB, 16 trang )

ANDROI
D

PROCESS MANAGEMENT

BY
HOANG VAN KIEN
HOANG HUY KHANH
PHUNG DUC LUAN


ANDROID

APPLICATION FUNDAMENTALS
PROCESS LIFE CYCLE


Application Fundamentals

04:52:53
PM

Application Components

Android
Android is
is multi-user
multi-user OS,
OS, each
each application
application


has
has it’s
it’s own
own user
user ID
ID
(because
(because of
of security
security reasons).
reasons).
Each
Each application
application has
has it’s
it’s own
own VM(virtual
VM(virtual
machine),
machine), to
to provide
provide isolation
isolation from
from other
other
process.
process.
Each
Each application
application has

has it’s
it’s own
own process.
process.
Application
Application is
is aa combination
combination of
of
components.
components.

APPLICATION
PROCESS
COMPONENT
COMPONENT
COMPONENT
COMPONENT


Application Fundamentals

04:52:53
PM

Application Components

Activities

An activity represents a single

screen with a user interface,
in-short Activity performs
action on the screen.

Services

A service is a component that
runs in the background to
perform long-running
operations.

A
S

B

C
A

Broadcast Receivers
Broadcast receivers simply
respond to broadcast messages
from other applications or from
the system.

Content Providers

A content provider component
supplies data from one
application to others on request.


Other Components

There are additional
components which will be used
in the construction of above
mentioned entities.


Application Fundamentals

04:52:53
PM

Application Components

First Activity

Second Activity

Click me!

This is second
activity


Application Fundamentals

04:52:53
PM


Application Components
Your
Your app
app can
can use
use another
another app’s
app’s components
components

YOUR APP

Use Email app to write
email

Write Email

Get Email Address

Use Contacts app to
get email address

Send Email
Use Email app to send
email


Application Fundamentals


04:52:53
PM

Activity Stack
Activity Stack
Activity 1

Previous Activities

Removed to
free resources

Activity 2



Activity 3

Activity n-1
Last Running Activity
Back button pushed or
Running activity closed

New Activity Started

New Activity

Running Activity



Application Fundamentals

04:52:53
PM

Activity Lifecycle
New Activity
1. onCreated()

4 states of an activity.

2. onStart()
3. onResume()

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.

Running

onResume()

onPause()


Paused

3. onResume()
2. onStart()

<<kill>>
onStop()

1. onRestart()
Stopped

onDestroy()

Destroyed

<<kill>>


Application Fundamentals

04:52:53
PM

Activity Lifecycle
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.

New Activity
1. onCreated()
2. onStart()
3. onResume()
Running

onResume()

onPause()

Paused

3. onResume()
2. onStart()

<<kill>>

onStop()

1. onRestart()
Stopped

onDestroy()

Destroyed

<<kill>>


Android Process Lifecycle

04:52:53
PM

Android Process

For
For each
each application
application android
android creates
creates aa
new
new process
process with
with single
single thread

thread of
of
execution(i.e
execution(i.e main
main thread)
thread)
By
By default
default all
all the
the components
components run
run in
in
same
same thread(main
thread(main thread).
thread).
In
In low
low memory
memory situations
situations aa process
process is
is
decide
decide to
to kill
kill based
based upon

upon the
the number
number of
of
inactive
inactive components
components of
of that
that process.
process.
AA process
process which
which have
have more
more number
number of
of
inactive
inactive components
components should
should be
be killed
killed
first.
first.

APPLICATION
PROCESS
THREAD
COMPONENT

COMPONENT
COMPONENT
COMPONENT


Android Process Lifecycle

04:52:53
PM

Android Process States
Process Priority

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

Active Process

Highest

Visible Process
Service Process
Background Process

Empty Process

Lowest


Android Process Lifecycle

04:52:53
PM

Android Process States
Process Priority

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

Active Process

Highest

Visible Process
Service Process
Background Process
Empty Process

Lowest



Android Process Lifecycle

04:52:53
PM

Android Process States
Process Priority

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.

Active Process

Highest

Visible Process
Service Process
Background Process
Empty Process

Lowest


Android Process Lifecycle


04:52:53
PM

Android Process States
Process Priority

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.

Active Process

Highest

Visible Process
Service Process
Background Process
Empty Process

Lowest


Android Process Lifecycle


04:52:53
PM

Android Process States
Process Priority

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.

Active Process

Highest

Visible Process
Service Process
Background Process
Empty Process

Lowest


THANKS FOR LISTENING!




×