Android — foregroundServiceType

Vairavan Srinivasan
3 min readNov 17, 2019

Android 10 SDK introduced foregroundServiceType for services. It could be one of these values.

“connectedDevice” | “dataSync” | “location” | “mediaPlayback” | “mediaProjection” | “phoneCall”

One of the intended use case is to support background location access for a user initiated action documented here. This ensures that app when backgrounded after a user initiated action like Navigation can still continue to get location updates without requesting background location permission (ACCESS_BACKGROUND_LOCATION) which is more likely to be denied by privacy concerned users.

FusedLocationProviderClient has the following behavior tested in Android 10 with Google Play Services (version 19.6.29)

  1. Activity requesting location updates from a resumed state without any special action when paused. Activity receives location updates only when in foreground state (resumed) but not in backgrounded state (paused). Location updates continue as and when the activity is resumed.
  2. Activity requesting location updates from a resumed state and starts a service when paused. Activity receives location updates only when in foreground state (resumed) but not in backgrounded state (paused). Location updates continue as and when the activity is resumed.
  3. Activity requesting location updates from a resumed state and starts a foreground service when paused. Activity receives location updates only when in foreground state (resumed) but not in backgrounded state…

--

--