I am the developer of a simple Android app that records location movements on behalf of the user. One can start the recording from the main Activity as well as from a Quick Tile. The recording takes place in a Foreground Service that displays a notification.
I recently updated the dependencies to targetSdkVersion 34
. Since then the recording service cannot be started from the app's Quick Tile anymore.
This is how I start the recording Foreground Service from a Quick Tile:
- the app registers a
TileService
- the
TileService
listens for taps on the Quick Tile inonClick()
- the recording Foreground Service is started from within the
TileService
viaapplication.startForegroundService(intent)
This setup used to work with targetSdkVersion 33
.
On targetSdkVersion 34
a tap on the Quick Tile causes a crash. The log shows:
android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service org.y20k.trackbook/.TrackerService
I looked at the Android 14 features and changes list and specifically at Restrictions on starting activities from the background. But I fail to see what changed between Android 13 and 14 that affects my case.
I considered the following solutions:
- Start an
Activity
from theTileService
that in turn starts the Foreground Service. This approach seems to be clunky. - Implement the recording functionality into the
TileService
and try to promote it to a Foreground Service and show the notification from within theTileService
What do you think? Can anyone come up with a better solution?