43
© Peter Späth 2018
P. Späth,
Pro Android with Kotlin
,
https://doi.org/10.1007/978-1-4842-3820-2_5
Chapter
5
Broadcasts
Android broadcasts are messages following the publish-subscribe pattern. They are sent
across the Android OS, with the internals
hidden by the Android OS, so both publishers and
subscribers see only a lean asynchronous interface for sending and receiving messages.
Broadcasts can be published by the Android OS itself, by standard apps, and by any other
app installed on the system. Likewise, any app can be configured
or programmed to receive
the broadcast messages they are interested in. Like activities, broadcasts can be explicitly
or implicitly routed, which is the responsibility of the broadcast sender to decide.
Broadcast receivers are declared either in the
AndroidManifest.xml
file or programmatically.
Starting with Android 8.0 (API level 26), the developers of Android have abandoned the usual
symmetry between XML and programmatic declaration of broadcast
receivers for implicit
intents. The reason is that the general idea of imposing restrictions on processes running in
background mode, especially related to broadcasts, resulted in a high load on the Android
OS, slowing devices down considerably and leading to a bad user experience. For that
reason, the declaration of broadcast receivers inside
AndroidManifest.xml
is
now limited to
a smaller set of use cases.
Note
You will want to write modern apps that are runnable in Android 8.0 and newer. For that
reason, take this broadcast limit for implicit intents seriously and make your app live within that
limitation.