Please provide the following:
- SDK Version: 38.0.0
- Platforms(Android/iOS/web/all): Android
My application keeps crashing whenever I try to open it for the second time. It works the first time I open the app. I have defined task manager globally in app.js like this:
console.log(‘task log’, TaskManager.isTaskDefined(‘background-location-task’));
if (!TaskManager.isTaskDefined(‘background-location-task’)) {
TaskManager.defineTask(‘background-location-task’, async ({ data, error }) => {
if (error) {
console.log(error);
return;
}
if (data) {
const { locations } = data;
// console.log(‘location is’, locations);
const client = await getLoginClient();
client
.post(‘cook/lat-long’, {
current_lat: locations[locations.length - 1].coords.latitude,
current_long: locations[locations.length - 1].coords.longitude,
})
.then((response) => {
console.log(‘Posted’, response);
})
.catch((error) => {
console.log(‘Error is’, error);
});
}
});
}
and then I reference this task in the initial screen after login like this:
componentDidMount = async () => {
await Location.startLocationUpdatesAsync(‘background-location-task’, {
accuracy: Location.Accuracy.lowest,
timeInterval: 1800000,
});