LightBlog

mardi 5 septembre 2017

Documentation Error: Manifest Registered Broadcast Receivers Receive ACTION_SHUTDOWN Intents in Android 8.0

Android uses broadcast intents for a lot of things. App developers can listen for them to perform certain actions, such as when the MEDIA_MOUNTED broadcast intent for applications to know when an SD card has been mounted as storage. As an app developer, you can program broadcast receivers for this, then call a function whenever media is mounted, for example, to change the app’s default storage directory to the SD card. This kind of thing is what broadcast intents are used for. They are mostly used to broadcast certain system events to any applications that may need that information. Broadcast receivers need to either be registered in the Android Manifest file or programmatically when in the foreground.

Due to an abundance of memory thrashing caused by many different developers implementing all sorts of broadcast receivers for frequently firing intents, Google decided to restrict access to most of these broadcast intents in Android 8.0 Oreo. The company recognized, though, that there were a couple of important broadcast intents that are okay to still be listened for since they do not occur all that often and thus have little chance of causing memory issues. They published a whitelist of implicit broadcast intents that Android applications can still listen for by registering broadcast receivers in the Android Manifest. This is an extensive list and covers just about everything you as an app developer may need, with one exception.

It appears Google did not list a broadcast intent that is used by many applications. This is the ACTION_SHUTDOWN broadcast intent. This intent is sent when the device is shutting down, which can be very important to app developers so they can quickly wind down whatever the app is doing before the process is killed. Despite this broadcast intent not appearing in the list of whitelisted intents, applications can in fact still listen for it via a Manifest-registered broadcast receiver according to a commit on the Android Git, just Google forgot to include it in their list.

This is great that it is actually whitelisted, as Google removing the ability from applications to detect when the device is shutting down would be bad for both users and app developers, as some applications would no longer be able to quickly save work before a device shutdown. We’re not entirely sure why this broadcast intent isn’t listed on Google’s page for developers, but we spoke with veteran Android developer CommonsWare and he agrees that it’s likely a simple documentation error on Google’s part. It wouldn’t be the first time this has happened, according to him.



from xda-developers http://ift.tt/2f0hZ7S
via IFTTT

.

Aucun commentaire:

Enregistrer un commentaire