Lecture 15: Introduction to Broadcasts Flashcards
Broadcasts in Android are a way of ____
notifying other applications or activities that some kind of event has taken place
The Android system itself uses broadcasts to notify applications when ___
system events have taken place
Applications may set up ___ to read broadcasts and ___ to send them
Applications may set up ___ to read broadcasts and ___ to send them
The most common purpose of a broadcast receiver is to receive __ notifications
system level
Introduction to Broadcasts
- ACTION_BATTERY_LOW
- ACTION_CHARGING
- ACTION_HEADSET_PLUG
- ACTION_USB_ACCESSORY_ATTAHED
- ACTION_DATE_CHANGED
Write code to declare a broadcast receiver in the app manifest
<receiver>
<intent-filter>
<action></action>
</intent-filter>
</receiver>
The broadcast receiver takes an ___, which in turn names an __ that we will be “listening” for
- intent filter
- action
____ is required if using external broadccasts, if only listening for internal broadcasts this can be ___
- exported=true
- false
Once the receiver has been declared in the app manifest, you can make a ___ for the receiver. It overrides one method called onReceive which ___
- Java Class
- opens an activity and displays a toast popup
Manifest-declared receivers can ____ when they receier a ___
- wake up
- broadcast
Manifest-declared receivers are always ___ for broadcasts
listening
_____ receivers cant be turned off and will aways trigger
Manifest-declared
Receivers are __ on application install and then treated as separate ___ for your application
- registered
- launching entrypoint
When a broadcast is made and caught by the receiver, ___
the OnReceive method is called and the broadcast receiver is “active”
Once the OnReceive method resolves, the receiver ___
returns to its dormant “waiting” state
You can declare a broadcast receiver without any manifest entry, this known as a ___, as its registered with the ___
- context-registered receiver
- current context
Context-registered receivers exist only for as long as the ___ exists
containing context
You can declare a broadcast receiver without any manifest entry, this is known as a ___, as its registered with the ___
- context-registered receiver
- current context
To declare a context-registered receiver, you need to create an instance of the ___ and call the ___ with a ___
- Receiver class
- registerReceiver()
- context, the receiver, an intent filter, and an exported flag
Both contextual and manifest registered receivers can use the same underlying declared ___ and both will call the overridden ___ method when a ___
- Broadcast Receiver
- OnReceive()
- broadcast is received
Contextually registered receiver will disappear and ____ when the context disappears, while the manifest registered receiver will ___
- stop listening
- always listen
To close an existing context-registered receiver you call ___ and pass it the ___
- unregisterReceiver()
- BroadcastReceiver object
When closing a context-register receiver, you will close all ___ and ___ of the receiver class that have been registered. You cannot selectively deregister ___ receiver from the ___
- intent filter
- exported flag versions
- one
- underlying class
Generally you dont need any ___ to listen to most normal system level broadcasts
special permissions
The broadcast space should be considered ___
global
To avoid apps doing malicious ats through sending broadcasts, Android lets you apply __ when receiving or sending broadcasts
optional permissions
___ can demand the broadcasts have necessary permission, while ___ can demand that receivers have a necessary permission
- Receivers
- Broadcaster
Besides permissions another danger that comes to working with broadcast receivers (particularly manifest-registered receivers) is ___
performance
If a particular broadcast action has many receivers listening to it that action may result in ___
multiple apps being launched at once from those receivers
___ receivers are preferred where possible to help limit potential performance issues
Context-registered