Broadcast Receiver Flashcards

1
Q

What is BroadcastReceiver?

A

It receives broadcast events from either other apps or Android system.

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

How do you get a complete list of system broadcast actions?

A

See the BROADCAST_ACTIONS.TXT in Android SDK

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

What are the changes made to BroadcastReceivers since Android 7(Nougat)?

A

Android does not send ACTION_NEW_PICTURE and ACTION_NEW_VIDEO
You need to use context-registered broadcast receiver for CONNECTIVITY_ACTION

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

What are the changes made to BroadcastReceivers since Android 8?

A

You need to use context-registered receivers for most implicit broadcasts

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

What are the changes made to BroadcastReceivers since Android 9?

A

NETWORK_STATE_CHANGED_ACTION does not receive user location or PII data

System does not send SSIDs, BSSIDs, connection info, or scan results. Use getConnectionInfo() instea

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

How do you register a BroadcastReceiver using context?

A
  1. Subclass BroadcastReceiver and implement onReceive(Context, Intent)
  2. Create an instance of it
  3. Create an IntentFilter and register the receiver by calling registerReceiver(BroadcastReceiver, IntentFilter)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Under what condition a BroadcastReceiver receives an event?

A

As long as the context is valid.
If it’s registered in an Activity, it’s valid until onDestroy() is called.
If it’s registered in an Application, it’s valid as long as your app is running.

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

When should you unregister a BroadcastReceiver?

A

onDestroy() if you registered in onCreate()

onPause() if you registered in onResume()

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

When is your BroadcastReceiver is considered to be a foreground process?

A

When the code in onReceive() is being executed.

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

Under what condition should you consider using background thread?

A

If the task is expected to run more than 16ms

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

How should you manage a long running task invoked by your BroadcastReceiver?

A

You should use either goAsync() or JobScheduler

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

What are the 3 ways to send a broadcast?

A
  1. sendOrderedBroadcast(Intent, String)
  2. sendBroadcast(Intent)
  3. LocalBroadcastManager.sendBroadcast()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly