expo: Expo keeps stopping when the app is killed while background location methods
š Bug Report
Summary of Issue
I registered a task for receiving the location updates in the background using Location.startLocationUpdatesAsync(taskName, options), And defined a task in the global scope using TaskManager.defineTask(taskName, task). The app frequently crashes when killed if the background task is active.
-
The Expo client refuses to start unless clearing its storage on Android.
-
The standalone app starts after at least two trials with a crash message.
Environment
- expo:
^38.0.0 - expo-task-manager:
~8.3.0 - expo-location:
~8.2.1
Screenshot
Steps to Reproduce
1- Location.startLocationUpdatesAsync
2- TaskManager.defineTask
3- Kill the application.
Expected Behavior vs Actual Behavior
- Expected behavior: The running task terminates smoothly.
- Actual behavior:: The running task is killed, and the app can be restarted without a crash message.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 10
- Comments: 40 (3 by maintainers)
I have tested the background location methods with Expo SDK 39, and I still get the same behavior as before, i.e. the app crashes if it is āswipedā away while the background location task is running. Iāve tested it on emulators with Android 9, 10 & 11, as well as on a real device with Android 11.
Iām really disappointed, as I desperately need this feature to work and had put all my hopes in the new version solving these issues (as described in the CHANGELOG for expo-location / expo-task-manager).
No problem. Something like this is what i have.
Then you run this in your main app navigator when the user is logged into your app. If they are signed out this component will not render and will not try to send background info to the server.
Iād consider this a serious issue. The background location feature is not working on Android and crashes the dev client and standalone apps.
@michaelkleinhenz just for clarity, and understanding for everyoneā¦
When you said you tried different versions of the dependency, Iām assuming you didnāt actually eject the project? If thatās the case it makes sense that it still āDoesnāt Workā on Expo 38, because the bug is in native code.
In order to test that those versions did fix the issue, you would need to be testing with an ejected project in the bare flow.
If you tested it with an bare/ejected project, then we should address that by looping in the person who fixed it originally, but I donāt believe that is the case.
These definitely seem like the same issue. @m-jachym they can fix it, and I think they have⦠but the issue is in native code, not JavaScript. In order to fix the issue they need to compile a new root binary for the managed workflow, which Iām sure is no small task. They have to update their CI to run the new release, development apps, along with many other things. If you are concerned about needing this fix sooner, you can always eject, to the bare workflow. There are pros and cons to each flow, and the managed one is that you are relying on Expo to do all the complicated things you donāt want to do.
I am still not convinced that it is actually fixed in 39. I havenāt seen a PR that directly refers to this issue. And youāre right, this is a major issue in an essential component. This should be fixed asap and with a hotfix. It is clearly understandable and clearly verifyable. And given that there are mutiple issues related to this issue, has a bit of gravity to it.
My fear is that this is an issue that exposes some deeper issues that are not easily fixable. Iāve seen a few source comments like āmore checks for NPEs, if this does not help, we have a deeper issue with thread safetyā¦ā. Those stuff makes me concernedā¦
I am also experiencing this issue and encountering the, āCannot initialize app loader. host.exp.exponent.taskManager.ExpoHeadlessAppLoaderā error. This occurs on an Android simulator when testing using Expo and using a standalone app published to the Google Play store.
Could someone confirm that this error does not occur prior to SDK 38 before I try downgrading?
Edit: no luck with SDK 37 š¦
Edit 2: I got it working after ejecting. Iām gonna miss expo publish š
Ok, but this solution only works if the app is in the foreground and used. That will not work for me, sadly, as I need a true background task to fech location and notify the user if some location matches.
In the meantimeā¦I created my own ābackground taskā for location on android only. It will poll the users location and send it up while the app is not killed⦠It will tie me over until the 39 release.
This looks like the issue in https://github.com/expo/expo/issues/9415
@ankit-kumar615 - this is not related to this issue. please create a new issue with more info if you believe this is a bug in expo code.
A project which was working fine a couple of days ago (sdk 26.0.0) has stopped working now. When trying to open it, the app crashes with only the āExpo keeps stoppingā error message. I proceeded to update the cli, the sdk and the android app to their latest versions, however, even now when i run a project with expo init and expo start, the app simply crashes. The apps in the Featured section of the expo android app seem to be working fine. Does anybody have any experience with this? This has pretty much killed all the expo projects i am working on and any insight would be greatly appreciated
@Obversity the linked ticket states it will go out in 39
I am encountering possibly the same issue (similar stacktrace), but I am not making any use of location services.
I get the following stacktrace upon startup of the app (only when built as standalone .apk):
It doesnāt work that way. The reason is that it is not supported by Expo SDK 38. Have a look here to see an explanation for it.
Also tried to upgrade
expo-taskmanagerto 8.4.0, no luck, same crash.