7.3 Broadcasts & BroadcastReceivers Flashcards

Learn about the theory and implementation of Broadcasts and BroadcastReceivers

1
Q

Broadcast Definition

A

Messaging components used for communicating when an event of interest occurs

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

BroadcastReceiver Definition

A

The components in you app that listen for app or system events and respond accordingly

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

What are the different types of broadcasts

A
  1. System broadcasts: delivered by the system

2. Custom broadcasts: delivered by your app

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

How do system broadcasts work?

A

These broadcasts are wrapped in an Intent object:
- The intent object’s action field
contains event details
-(e.g. android.intent.action.HEADSET_PLUG)

  • Intents can also contain more data
    about the event in the extra field
    -(e.g.as a boolean for whether or not the
    headset is connected or disconnected )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What must an application do to receive a system broadcast?

A

Interested apps must register a component to “listen” for these events via a BroadcastReceiver

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

When do you use custom broadcasts?

A

When you want your ap to take action without launching an activity.

For example, to let other apps know that data has been downloaded and it’s available for those apps.

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

What are the different types of custom broadcasts?

A
  1. Normal broadcasts
  2. Ordered broadcasts
  3. Local broadcasts
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the methods associated with the different types of custom broadcasts?

A
  1. Normal broadcasts:
    sendBroadcast( )
  2. Ordered broadcasts:
    sendOrderedBroadcast( )
  3. Local broadcasts:
    LocalBroadcastManager.sendBroadcast( )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What makes normal broadcasts different from the other types?

A

It sends broadcasts to all registered receivers simultaneously, in an undefined order.

They can’t propagate (spread) the results among themselves

They cannot cancel the broadcast

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

An example of a normal broadcast

A
public void sendBroadcast() {
Intent intent = new Intent();
intent.setAction("com.example.myproject.ACTION_SHOW_TOAST");
   // Set the optional additional information in extra field.
intent.putExtra("data","This is a normal broadcast");
sendBroadcast(intent);
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly