Explore key concepts related to broadcast receivers and system events in Android development, including intent filters, broadcast types, registration methods, and lifecycle behaviors. This quiz helps reinforce understanding of handling system broadcasts and building responsive applications using broadcast receivers.
Which component is specifically designed to respond to announcements or 'broadcasts' from the Android system or other apps?
Explanation: A Broadcast Receiver is the correct answer because it receives and responds to broadcast messages from the system or other apps. Service Module is incorrect as it handles background processing tasks. Content Provider manages shareable data, not broadcasts. Activity Handler is not a defined component and does not react to system broadcasts.
In Android, what is the difference between registering a broadcast receiver in the manifest and registering it at runtime in code?
Explanation: Manifest-registered receivers are always available for system-wide broadcasts, even when the app is not running. Runtime receivers are active only when the app or component is running and are unregistered automatically when it stops. The other options are incorrect: local broadcasts are not associated with manifest, and both methods are not identical.
Which manifest entry is required to specify which broadcasts a receiver will respond to?
Explanation: u003Cintent-filteru003E defines the types of broadcasts a receiver listens for in the manifest. u003Ccategoryu003E is used for specifying additional constraints on an intent, but it is not the main element. u003Cpermissionsu003E deals with security, while u003Caction-handleru003E is not a valid manifest tag.
Which of the following is an example of a system broadcast that a receiver can listen for?
Explanation: android.intent.action.BOOT_COMPLETED is a standard system broadcast sent after the device finishes booting. application.intent.TEST_NOTIFICATION and mypackage.NEW_EVENT_RECEIVED are typical formats for custom broadcasts. android.intent.FAKE_ACTION is not a valid or commonly used broadcast action.
How long does a BroadcastReceiver stay active after its onReceive method is called?
Explanation: A BroadcastReceiver is only active while its onReceive method executes and is considered finished immediately after. It does not remain active indefinitely nor for a fixed 10 seconds. It is irrelevant whether the app stays open; the receiver's lifecycle is tied to onReceive.
Which type of broadcast is only available within the same application and is typically used to communicate between components of that app?
Explanation: Local broadcasts are restricted to the app they are sent from, improving security and efficiency. System broadcasts are sent by the system to all interested apps. Network and public broadcasts refer to different concepts and are not used for intra-app communication.
What is a key feature of ordered broadcasts in Android?
Explanation: Ordered broadcasts pass the message to each receiver in a specific order, allowing one to modify or even abort the broadcast. The message is not delivered simultaneously to all receivers. While ordered broadcasts are commonly used, they are not restricted to system-only events, and instant delivery is not guaranteed.
Which characteristic best describes a sticky broadcast in Android?
Explanation: A sticky broadcast stays in the system after being sent so that future receivers can access the last broadcasted data. They do not necessarily require explicit permissions, nor are they limited to only manifest-declared receivers. Encryption is not an inherent property of sticky broadcasts.
Why might you specify a permission in the manifest for a broadcast receiver?
Explanation: By specifying a permission, you control which apps can send broadcasts to your receiver, enhancing security. Specifying a permission does not impact speed, background operation, or updating capabilities of the receiver, making those options incorrect.
If an app needs to update its user interface after the device loses network connectivity, what broadcast action should the receiver listen for?
Explanation: The android.net.conn.CONNECTIVITY_CHANGE broadcast notifies apps of changes in network status, enabling UI updates. NEW_TASK and USER_PRESENT are unrelated to network status, and PHONE_STATE_CHANGED pertains to telephony changes, not connectivity.