This ONLY purpose of this project is to demonstrate a problematic behaviour of Foreground Services of type location on Android 11 Preview.
An APK is available under app/build/outputs/apk/debug/app-debug.apk
- Install the app on Android 11 Preview
- Open the app
- In the location permission popup, choose "Only this time"
- Tap the "start" button (logcat will show logs from the
PositionMonitor
about received locations) - Tap the home button (app should not be visible anymore, foreground service notification is still visible, locations are still received)
- Run the following command to simulate the service being killed and restarted:
adb shell ps | grep com.example.foregroundservicedemo | awk '{print $2}' | xargs adb shell run-as com.example.foregroundservicedemo kill
- Service is restarted.
- Location permissions are still granted because the service was not stopped by the user but by the system.
- Location udpdates are received.
- Service is restarted.
- Location permissions are not granted anymore. See logcat:
PositionMonitor: start() ACCESS_FINE_LOCATION:false - ACCESS_COARSE_LOCATION:false
- Location updates are notreceived.
If at step #3, the option "While using the app" is selected by the user, it works with the EXPECTED behaviour: permissions are granted and location updates received.