Lecture 12: Intro to Services Flashcards

1
Q

A service is launched from the __ as the __ that called it

A
  • same thread
  • host
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Can services run in parallel?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Services have a lifetime that may be controlled by the ___ or __

A
  • service itself
  • outside forces
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the 2 broad categories services can be split into based on their user visibility

A
  • foreground services
  • background services
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

A __ service doesnt require user UI interaction, but does require that a notification be shown to let the user know the serivce is running

A

foreground

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

A __ service a a hidden service. Not required to provide a notification or provide any indication that its running

A

background

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

__ services are good for silently updating or managing aspects of your app without requiring user interaction

A

background

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are some of the limitations you may do with background services since they provide no indication that theyre running

A
  • Give them a allowance of time to access sensitive info since the last user noticeable action
  • May be restricted from using certain components
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

When are bound services essential?

A

When a service must be able to pass data off to other activities or services in real time rather than editing data on disk for others to read

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

A __ service creates a communication link between itself and one or more binders that allows for data transfer back and forth

A

bound

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What 3 things do you need to create a service?

A
  • An entry in the app manifest file declaring the service with a name and other descriptors
  • A java class that extends the standard service class for android and implements the 4 lifecycle functions required
  • An intent used to launch the service
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Services must be declared within your app manifest within a __ tag and the only required field is the ___

A
  • <service>
    </service>
  • name of the service
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Each service is defined it its own __ which ___ from the default Android ___ class

A
  • class
  • extends
  • service
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Within the service class we must __ a set of __ for the service

A
  • override
  • lifecycle functions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Describe the service lifecycle

A
  • Begins with onCreate() and ends with onDestroy()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Unbound services are called with a __ and call the __ method

Bound services use __ and call on the __ and __

A

startService(), onStartCommand()

bindService(), onBind(), onUnbind()

17
Q

We can think of each lifecycle function as being some block of code we want to execute at a __ of the __

A
  • very specific stage
  • services life
18
Q

When a service terminates depends on the ___

an __ will run ___ if allows

A

service type

unbound service, indefinitely

19
Q

Started or unbound services must use ___ to terminate themselves when they have ___

A

stopSelf()

completed their tasks

20
Q

Bound services will automatically be __ when all ___ are ___

A

destroyed

bound components, unbound

21
Q

What does the constant startMode do?

A

An int value that tells the system how to handle unexpected termination

22
Q

What does START_NOT_STICKY tell the system?

A

Not to restart your service after exiting

23
Q

What does START_STICKY tell the system?

A

To restart the service but with a null intent

24
Q

What does START_REDELIVER_INTENT tell the system?

A

Restart and resend the original intent when launching the service

25
Q

What is the safest way to tell the system to handle unexpected termination and why?

A

START_NOT_STICKY

Ensures service wont be dangling doing nothing

26
Q

How do you start a service in unbound mode?

A

Create an intent pointing to the service class and pass it to startService()