Junior — Middle
In which cases is it necessary to declare a Broadcast Receiver in the application's manifest file?
sobes.tech AI
Answer from AI
Broadcast Receiver must be declared in the manifest if you want it to:
- Receive system broadcast messages, which are sent by the system, such as device boot, network connectivity changes, etc.
- Work even if the application is not running (i.e., the receiver should be registered statically).
If the Broadcast Receiver is registered dynamically in code (via registerReceiver), then it does not need to be declared in the manifest, but it will only be active as long as the component (e.g., Activity or Service) is running.
An example of a system event that requires a manifest declaration:
<receiver android:name=".MyReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>