Hello,
I have been following the documentation here, relating to running a foreground service in Expo. This is for the gathering of location on Android devices when an app is minimised every X seconds.
From Android 10 + this requires a foreground service.
The expo documentation above states running a foreground service will work in the Android Emulator and an Android device.
Yet foreground services written using the code in the documentation above do not work when an app is launched using the android emulator, via the command expo start, for devices running on Android 10 or above. Minimise the app, no foreground notification, and no GPS updates are logged.
On Android 9 or lower, there is no requirement for a foreground service, and so location will continue to be gathered when an app is minimised.
The codebase above does work when the app is compiled however - either using npx expo run:android or using Expo EAS and downloading the APK to run locally on a physical device.
This leads me to think there is something about the expo package which is not compatible with foreground services, at least prior to there being a real ‘build’ of the android project with the /android/ folder etc.
Is this a known limitation or bug? I note a similar forum comment here, no replies.
Final comment: I suspect the probable cause (given it only affects Android 10+) is that the requirement for a foreground service is not compatible with the ExpoGo app - or Expo’s Managed Workflow - whatever the terminology is to refer to the stage prior to the compilation of a separate /android/ folder via expo pre-build and expo run (*Expo eject is now deprecated as of Jan 2023 so I will not use that terminology). I do not have enough familiarity with Expo to be using the right words here.
Photos are clearer than my words:
I am attaching a screenshot of the app. On the left I am running in an emulator via expo start, minimised the app, no foreground service, no gps updates.
On the right is the same codebase, running on a real device and composed using npx expo run:android - as you can see, minimise the app, and a foreground service exists, GPS continues to work when app is minimised.
Any comments appreciated.
This is not intended to start a discussion about background services.