Closed Asghwor closed 2 years ago
Android 10 introduced background restrictions, maybe this is what causing the issue ? How did you implement background service ?
https://developer.android.com/about/versions/10/privacy/changes#background-activity-starts
Android 10 introduced background restrictions, maybe this is what causing the issue ? How did you implement background service ?
Thanks for answering!
The Android service is started when the user presses a tracking button in the app. It then starts a service that calls the JS side of the application every 30 seconds to run a callback that calls getCurrentPosition
and sends the data to the server.
I made it keep a notification sticked in the notifications area so the service would not be killed in the background.
Adding ACCESS_BACKGROUND_LOCATION
to AndroidManifest and asking for this permission after ACCESS_FINE_LOCATION
makes it work.
@Asghwor For background services which pkg used? I am in the same senior to send location to server but issue in bg. kindly help.
Environment
Run
npx react-native info
in your terminal and copy the results here.Platforms
Is this issue related to Android, iOS, or both ? Android
Versions
Please add the used versions/branches
Description
A callback is called every 30 seconds when it's either in the background or in foreground to get the current position and send to the server.
It works perfectly when the app is opened. But, as soon as the app is closed/minimized,
getCurrentPosition()
hangs until it times out. If there is no timeout, it just hangs indefinitely.The background service itself is running perfectly, as I've checked by sending mocked positions. It just hangs when calling
getCurrentPosition()
.This problem has only manifested itself in more recent versions of Android; more specifically, Android 10 on Sansung Galaxy phones. All energy saving mechanisms had been disabled.
Reproducible Demo
getCurrentPosition()
, where it'll hang.Expected Results
getCurrentPosition()
would return the current device position and the background service would successfully finish its task.