We are about to update our App Android API 26. In the documentation about Broadcast receiver it says that
Apps that target Android 8.0 or higher can no longer register broadcast receivers for implicit broadcasts in their manifest
Implicit broadcast receivers are described as
a broadcast that does not target that app specifically. For example, ACTION_PACKAGE_REPLACED
So I assume that android.intent.action.BOOT_COMPLETED
is considered an implicit receiver.
Further it states that implicit receivers must be registered within an Activity
by using Context.registerReceiver()
. But that wouldn't make sense for a receiver, which is listening for the BOOT_COMPLETED
event.
What is the proper way to handle this? Can i keep this receiver in my manifest?
Receiver can be registered via the Android manifest file. You can also register and unregister a receiver at runtime via the Context. registerReceiver() and Context. unregisterReceiver() methods.
You can put a flag into your class or activity. Put a boolean variable into your class and look at this flag to know if you have the Receiver registered. Create a class that extends the Receiver and there you can use: Singleton pattern for only have one instance of this class in your project.
Broadcast Receiver by default runs on Main Thread only.
There are mainly two types of Broadcast Receivers: Static Broadcast Receivers: These types of Receivers are declared in the manifest file and works even if the app is closed. Dynamic Broadcast Receivers: These types of receivers work only if the app is active or minimized.
BOOT_COMPLETED is still accepted.
https://developer.android.com/guide/components/broadcast-exceptions.html
No need to change anything. Make sure you test in Android 8.
ACTION_BOOT_COMPLETED
is on the implicit broadcast whitelist, and so you can register for it in the manifest.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With