-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[native code] foreground service is killed and never restarted #1042
Comments
Status Update 1. make sure that it runs when the app is launched (e.g. onStart and onResume) 2. see if the function is launched in the background (add additional logs if needed) 3. check to see if the foreground service is actually created when the function is launched in the background Thoughts so far What is stumping me, however, is why reopening the app did not trigger the foreground service to restart. Based on the logs, it still seems like it is tracking and/or detecting movement as
I remember seeing in the code for
I'm not sure if this matters or not, but I figured I'd bring it to attention regardless just in case we aforementioned state could be blocking us from launching the foreground service. Potential Solution |
I was investigating into this issue a bit more today, and I ran into something weird. I said above, in response to the first question, that...
Today, for some reason, the foreground service doesn't seem to restart whenever I reload the app. I'm not really quite sure why it doesn't restart, but nonetheless I think this reinforces the idea of the solution I mentioned above, to manually check the foreground notification each time we load the app. I put together a draft pr here where we can see the necessary change that would need to be made. If the code decides to work and the foreground service loads properly, I decided to put it in Regardless, I did some quick tests with this code and it seems to consistently restart the foreground service whenever I kill it. As mentioned above I still need to do more testing and think about this a bit more but I wanted to get it out here. Going forward I also want to play around with the airplane mode issue and see if this solution could potentially fix it as well. |
@louisg1337 couple of updates from my current trip:
|
Status UpdateI was able to write the code for the changes listed above, and it can be found in this draft PR. CodeI essentially implemented what was stated above, I put the I decided to put it in I could totally be wrong here with my assumptions, and it may not even make a difference if we have 1 or 2 calls, so please let me know about this. TestingI tested two different scenarios which were...
Please let me know @shankari what you think about both issues I talked about above, being the |
|
I have noticed this multiple times on my phone recently. The foreground service is killed, so we don't get fine-grained locations, and is never restarted. I assume that the background services are also killed, so we don't even get batched callbacks.
Note that, since Android 12+, apps cannot start foreground services while the app is running in the background
https://developer.android.com/develop/background-work/services/foreground-services
UNLESS "The user turns off battery optimizations for your app."
That's why we now have users turn off battery optimizations for the app during installation. However, on my phone:
I finally had to turn tracking off and on for it to actually start.
We need to look at the code that checks and restarts the foreground service
https://github.com/e-mission/e-mission-data-collection/blob/103b787db3347254488083714d178624ec76092a/src/android/location/TripDiaryStateMachineReceiver.java#L210
and:
onStart
andonResume
)(it might help to manually kill the foreground service during testing - see how I did this earlier
#838 (comment))
I have filed an internal issue with the logs.
The text was updated successfully, but these errors were encountered: