For an expo app that is not ejected and runs in the background, my goal is to do a location tracking periodically or when location changes.
I am sticking with Expo's base APIs including its Location, TaskManager API.
Location tracking only works for a first couple of times before it completely stops.
Following what was written in the Documentation here: https://docs.expo.io/versions/v32.0.0/sdk/location/, I was able to make an app that tracks location with the API: Location.startLocationUpdatesAsync of Expo. I had also defined a "Expo.TaskManager" and this should log a new location every time a new location is detected.
However, if the app runs in the background for more than a few seconds, geolocation service tracking no longer works. No further logging will not be written in the console.
Define Task:
TaskManager.defineTask(PUSH_LOCATION_IN_BACKGROUND, ({ data, error }) => {
if (error) {
return;
}
if (data) {
const { locations } = data;
console.log('locations are ', locations)
}
});
Start (register) the task:
await Location.startLocationUpdatesAsync('PUSH_LOCATION_IN_BACKGROUND', {
accuracy: Location.Accuracy.Balanced,
distanceInterval:3,
});
I expect that every time I change the location of my device (by either moving to a new location of faking my GPS data), I would receive a logging of the new location if the app runs in the background. However, as soon as the app enters the background, it only logs the data for a couple of times before it completely stops.
I would expect that the app will run stably in the background and if possible, avoid being killed by the OS even if the resource consumption in the device is already high.
And as someone who is not experienced in Android developemnt, do I need to set up an undismissable (user cannot dismiss it nor remove it by clicking on it) notification in order to keep the background task of the app alive? Can I do it with an unejected Expo app.