What is an implicit broadcast reciever in Android?


#1

I am migrating my application from 24 to 26 (Oreo). Android has introduced certain battery optimizations for apps targeting 26. One of them is regarding implicit broadcast receivers. From the documentation,

“As part of the Android 8.0 (API level 26) Background Execution Limits, apps that target the API level 26 or higher can no longer register broadcast receivers for implicit broadcasts in their manifest. However, several broadcasts are currently exempted from these limitations. Apps can continue to register listeners for the following broadcasts, no matter what API level the apps target.”

Source: https://developer.android.com/guide/components/broadcast-exceptions

Could you please explain what exactly is an implicit broadcast receiver? I see examples with System sent broadcasts and I am clear on that. Receivers that are registered in the manifest file with a custom string(prefixed with fully classified path) as the intent action and having a name that points to a class within the source code of the application - do they qualify as implicit or explicit broadcasts?

Example:

Are such receivers implicit or explicit?


#2

As stated in the broadcast overview, Implicit broadcasts are “broadcasts that do not target your app specifically.” Android is trying to improve user experience by preventing a whole bunch of apps from starting and executing some code at the same time.
My favorite example of an implicit broadcast receivers are the SCREEN_ON and SCREEN_OFF broadcasts, which fire every time a user locks or unlocks their phone. You could probably imagine the frustration a user would feel if every time they unlock their phone it slows way down because every single app is updating.

Most of the receivers you can register in the manifest are explicit broadcasts. The exceptions, a.k.a. implicit broadcasts you can register to receive in the manifest, are listed on the page you linked. A good example of the implicit broadcasts you can register to receive in the manifest is the ACTION_BOOT_COMPLETED broadcast. If you couldn’t register to receive it in your manifest, you’d never get it, because you would not have had a chance to programmatically register to receive it because the phone was off!

If you’ve created a custom broadcast, you can register to receive that in your manifest, like an explicit broadcast.

I highly recommend checking out the broadcast overview I linked above, there’s lots of great information there.