Broadcast Receiver Life Cycle

I want to have BroadcastReceiver

one that should be active forever (100%). Now if I have this registered in the Android manifest, will that be the case, or will it get killed when the application itself is destroyed by the Android framework?

Now I also have a service running in the foreground all the time. Will this make sure my application is never destroyed? And in turn, make sure that my receiver, which is registered in the Android manifest, remains active forever.?


source to share

1 answer

a BroadcastReceiver

( docs ) that is in the manifest is always active and it works even if the activity no longer works (think about receivers for an intent action android.intent.action.BOOT_COMPLETED

that fires every time the phone is turned on). Recipients that are defined and registered dynamically only work when the application starts (for example, LocalBroadcastManager registerReceiver(...)


See the receiver documentation which says:

Declares a broadcast receiver (a subclass of BroadcastReceiver) as one of the application components. Broadcast receivers allow applications to receive intents that are broadcast by the system or other applications, even when other components of the application are not running.

The service documentation says:

A foreground service is a service that is considered something the user is actively aware of and therefore not a candidate for a system to kill on low memory

Therefore, it is likely that the system will not kill the running application to which the service belongs.

So it looks like being able to read the documentation, which I think is comprehensive about the Android platform.



All Articles