byCedric / office-marathon

Example app for background location tracking in Expo
MIT License
61 stars 15 forks source link

I think there is infinite loop getting location data, is it okay? #2

Closed byyoungjin closed 3 years ago

byyoungjin commented 3 years ago

First of all, I really thank you for this really nice app. I learned something from this app making my own running fitness app.

Issue

  1. This app stop tracking locations in 5 minutes when the phone goes to sleep mode. Just like this issue https://github.com/expo/expo/issues/10712
  2. When phone awake from sleep mode, The tracking goes crazy. Not stop before I press the reset button several times.
  3. I think there is an infinite loop getting location data. And wonder there is no problem with it..?

Background info

I'm running into this issue https://github.com/expo/expo/issues/10712

when I run this sample app. It worked well, but not in sleep mode. Like I said above issue, It stops tracking after 3~ 5 min. But this app looks different from mine. when I restarted this simple app from sleep mode, its tracking logs go crazy, and not stop before I press the reset button several times.

At first, I thought it store the tracking locations that have not tracked while the phone was in sleep mode.

but it isn't. it just looked like storing several same locations.

So, I looked into the code and found nothing looks strange but this code below

I think this goes infinite loop. Is there no problem with this..? (onPollStorage update locations, locations update onPollStorage, new onPollStorage function trigger useEffect, and useEffect run onPollStorage) and I wonder is it related to that number 2 issue?

https://github.com/byCedric/office-marathon/blob/2ddfbb571e78b02957b8d2f3a04f473d23c83048/src/services/location/index.ts#L72-L92

byCedric commented 3 years ago

Oh, that's definitely possible! I kind of made this app in 2 hours, so it's not my best code, especially the part where it polls the location data from storage. I'll try to replace that code with something more event based, without polling.

As for the sleep stuff, I'm not able to reproduce it. I have used this app for a day, and it roughly registered most of the coordinates. It registered about 150 coordinates, which translates to a usage time of a rough 12.5 hours ((150 * 5) / 60 = 12.5).

byyoungjin commented 3 years ago

@byCedric I really thank you for your effort. 👍 But the problem keeps happening and I couldn't find anything from google for several days.. So I came back again.. Would you try

  1. timeInterval: 1000,
  2. android 10 simulator
  3. push start tracking
  4. turn off the simulator to sleep mode
  5. and wait 5 minutes?

I'm sure you can reproduce it!

just background..

I set the time as 1000 ms ( because I need to track a running person ) And I think this work on ios, not terminating process or app on sleep mode ( I tested about 1hour )

but on Android On Android 10 simulator, this stops on sleep mode. For me, it logs about 72 locations and stops. If I get out from sleep mode, It keeps logging.. ( for some reason It goes crazy.. ) The main problem is it stops tracking location on sleep mode..

and for some reason, I think expo SDK40 gives me a permission error like this below https://forums.expo.io/t/sdk40-android-unhandled-promise-rejection-error-not-authorized-to-use-background-location-services/46508/4

This makes me really exhausting. I want to know is it about google policy So I should wait for a while until expo team deals with it? or it's just a problem of me?