In Android O we have some new background limitations. For example we can only register implicit broadcasts via the Context.registerReceiver
method. When the system kills our process (e.g. as a result of low memory) the registered receivers will also be destroyed.
To reduce the chance that the system kills our process we have to tell the system that this process is still in the foreground. As per documentation an app is considered to be in the foreground if any of the following is true:
- It has a visible activity, whether the activity is started or paused.
- It has a foreground service
- Another foreground app is connected to the app, either by binding to one of its services or by making use of one of its content providers. For example, the app is in the foreground if another app binds to its:
- IME
- Wallpaper service
- Notification listener
- Voice or text service
If none of those conditions is true, the app is considered to be in the background.
What about TileService
(for quick setting tiles) which were introduced in Android N? When we register a TileService
as ACTIVE_TILE
in the mainfest file the system does not bind the service every time the tile becomes visible (as noted in this article) and therefore our service is bind to another application, in face the system process.
So is my application (as long as the tile is added to the quick settings pane) considered as foreground application? This would be nice because I do not need a persistent notification with this approach and it is nevertheless possible for the user to send my app in the background (by removing the tile)