Professional Documents
Culture Documents
d.schmidt@vanderbilt.edu
www.dre.vanderbilt.edu/~schmidt
Professor of Computer Science
Institute for Software
Integrated Systems
Vanderbilt University
Nashville, Tennessee, USA
Download
Activity
Socket
Download
Service
Socket
Send HTTP
GET request
Download
Activity
Download
Activity
Download
Activity
startService()
Download
Service
Download
Activity
startService()
Download
Service
Download
Activity
Download
Service
Download
Activity
Socket
Download
Service
Socket
Send HTTP
GET request
Download
Activity
Send reply
Download
Service
10
Download
Activity
Send reply
Download
Service
Download
Activity
Send reply
Download
Service
13
github.com/douglascraigschmidt/POSA-14/tree/master/ex/DownloadApplication
14
15
Programming
Started Services
(Part 1)
16
Download
Activity
Socket
Download
Service
Socket
17
Send HTTP
GET request
Intent intent =
DownloadService.makeIntent
(this, Uri.parse(url), downloadHandler);
startService(intent);
Download
Activity
18
developer.android.com/guide/components/services.html#CreatingStartedService
Download
Activity
19
Download
Activity
20
Download
Activity
21
Download
Activity
Download
Service
22
www.dre.vanderbilt.edu/~schmidt/PDF/Activator.pdf
has more info
Download
Activity
Download
Service
23
Download
Activity
Download
Service
24
Download
Activity
Download
Service
25
Download
Activity
Download
Service
26
Programming
Started Services
(Part 2)
27
Download
Activity
Download
Service
28
Download
Activity
Download
Service
29
Download
Activity
Download
Service
30
Download
Activity
Download
Service
31
Download
Activity
Download
Service
32
Download
Activity
Download
Service
33
Download
Activity
Download
Service
34
android-developers.blogspot.com.au/2010/02/service-api-changes-starting-with.html
Download
Activity
Download
Service
35
Download
Activity
Download
Service
36
Download
Activity
Download
Service
37
Download
Activity
Download
Service
38
Download
Activity
Download
Service
39
Design of the
Download Application
40
41
42
43
Intent
Download
Activity
startService()
44
send
intent
45
Intent
Download
Service
onCreate()
send
intent
onStartCommand()
46
Intent
Download
Service
onCreate()
send
intent
onStartCommand()
Intent
Download
Service
onCreate()
send
intent
onStartCommand()
3 Create a
Service
Handler
sendMessage()
handleMessage()
downloadImageAndReply()
47
worker
thread &
Handler
Intent
Download
Service
onCreate()
send
intent
onStartCommand()
3 Create a
Service
Handler
sendMessage()
handleMessage()
downloadImageAndReply()
48
worker
thread &
Handler
Intent
Download
Service
onCreate()
send
intent
onStartCommand()
3 Create a
Service
Handler
sendMessage()
handleMessage()
downloadImageAndReply()
49
worker
thread &
Handler
Intent
Download
Service
onCreate()
send
intent
onStartCommand()
3 Create a
Service
Handler
sendMessage()
handleMessage()
downloadImageAndReply()
50
worker
thread &
Handler
Intent
Download
Service
onCreate()
send
intent
onStartCommand()
3 Create a
Service
Handler
worker
thread &
Handler
sendMessage()
handleMessage()
downloadImageAndReply()
Intent
Download
Service
onCreate()
send
intent
onStartCommand()
4
Service
Handler
sendMessage()
handleMessage()
downloadImageAndReply()
52
Intent
Download
Service
onCreate()
send
intent
onStartCommand()
4
Service
Handler
sendMessage()
handleMessage()
downloadImageAndReply()
53
54
Intent
Download
Service
onCreate()
send
intent
onStartCommand()
Service
Handler
sendMessage()
Dequeue
Intent
& get file
handleMessage()
5
downloadImageAndReply()
55
Intent
Download
Service
onCreate()
send
intent
onStartCommand()
Service
Handler
sendMessage()
Dequeue
Intent
& get file
handleMessage()
5
downloadImageAndReply()
Intent
Download
Service
onCreate()
send
intent
onStartCommand()
Service
Handler
sendMessage()
Dequeue
Intent
& get file
handleMessage()
5
downloadImageAndReply()
57
Intent
Download
Service
onCreate()
send
intent
4
Service
Handler
sendMessage()
Dequeue
Intent
& get file
handleMessage()
5
downloadImageAndReply()
Client
Queue request
58
www.dre.vanderbilt.edu/~schmidt/PDF/CommandRevisited.pdf
has more info
Client
Queue request
Summary
60
Summary
The Download Application uses a
Started Service to retrieve & display
an image from a remote server
Download
Activity
Socket
Download
Service
Socket
61
Send HTTP
GET request
Summary
The Download Application uses a
Started Service to retrieve & display
an image from a remote server
When a Started Service is launched,
it has a lifecycle that's independent
of the component that started it
Download
Activity
Download
Service
62
Summary
The Download Application uses a
Started Service to retrieve & display
an image from a remote server
When a Started Service is launched,
it has a lifecycle that's independent
of the component that started it
A Service can run in the background
indefinitely, even if the component
that started it is destroyed
Download
Activity
Download
Service
63
Summary
The Download Application uses a
Started Service to retrieve & display
an image from a remote server
When a Started Service is launched,
it has a lifecycle that's independent
of the component that started it
Started Services are driven by
inversion of control
64
Summary
The Download Application uses a
Started Service to retrieve & display
an image from a remote server
When a Started Service is launched,
it has a lifecycle that's independent
of the component that started it
Started Services are driven by
inversion of control
65
Summary
The Download Application uses a
Started Service to retrieve & display
an image from a remote server
When a Started Service is launched,
it has a lifecycle that's independent
of the component that started it
Started Services are driven by
inversion of control
The Download Application
implementation is guided by
a common Android idiom for
concurrent Service processing
Intent
Download
Activity
startService()
Download
Service
onCreate()
send
intent
onStartCommand()
Service
Handler
sendMessage()
handleMessage()
5
downloadImageAndReply()
dequeue Intent
& download file
66
Summary
The Download Application uses a
Started Service to retrieve & display
an image from a remote server
When a Started Service is launched,
it has a lifecycle that's independent
of the component that started it
Started Services are driven by
inversion of control
The Download Application
implementation is guided by
a common Android idiom for
concurrent Service processing
This idiom is based on the
Command Processor pattern
Intent
Client
Activity
onCreate()
startService()
Service
Handler
Intent
Service
send
intent
onStartCommand()
queue
intent
3
Download
Service
sendMessage()
handleMessage()
onHandleIntent()
dequeue
intent
process intent