Broadcast Receivers Flashcards
What is a Broadcast Receiver?
1 of the 4 components. They are used to catch broadcast intents.
What do Broadcast Receivers catch?
Broadcast Intents.
What are the 5 steps of the Broadcasting Process? Describe each…
1) Create a Broadcast Receiver class that implements onReceive and extend BroadcastReceiver.
2) Register the Broadcast Receiver in the apps Manifest. <receiver>
3) Listen for a Broadcast Intent.
4) BroadcastReceiver receives the broadcast.
5) Call the onReceive method to respond to the broadcast in a specified way.</receiver>
What is a Broadcast Intent?
An intent that is broadcast by the system or an application. The broadcast is delivered to all registered Broadcast Receivers. An example is when the system sends out a low battery broadcast intent.
What can’t Broadcast Intents do?
Start an activity.
What methods sends a Broadcast Intent?
sendBroadcast( ).
What are the 2 types of Broadcast Intent? Define each…
System Broadcast Intent -> Send by the OS to notify user, apps and components of system events. For example, power connected or battery charged.
Custom Broadcast Intent -> A customised intent that is sent by an application under custom conditions.
Define what a Sticky Broadcast Intent is…
Intents that persist until they have been received by a Broadcast Receiver.
Where are Sticky Broadcast Intents held whilst waiting for a Broadcast Receiver?
In a cache.
Why are Sticky Broadcast Intents not suitable for sending sensitive information?
Because they are public when waiting to be received, thus aren’t suitable for sensitive information.
Define what a Non-Sticky Broadcast Intent is…
An intent that is discarded straight after it is sent. Thus, if a receiver doesn’t register it immediately, it doesn’t get store in the cache, but is destroyed instead.
What are the 3 methods that can be used to send custom intents?
sendBroadcast( )
sendOrderedBroadcast( )
sendStickyBroadcast( )
If an application wants to listen for a specific Broadcast, what does it need to do?
Register a Broadcast Receiver component in the manifest. The Broadcast Receiver must be registered to the intent.
To create a Broadcast Receiver, what class must you extends, and what method but be implemented?
MyReceiver extends BroadcastReceiver
Must define onReceive( )
What is the purpose of Broadcast Permissions in the Broadcast Intent?
Ensures that only Broadcast Receivers with the specified Permissions can receive the intent.