Skip to content
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

Not working on android simulator and real device in sleep mode. (related issue #2 ) #7

Open
byyoungjin opened this issue Jan 7, 2021 · 6 comments · May be fixed by #9
Open

Not working on android simulator and real device in sleep mode. (related issue #2 ) #7

byyoungjin opened this issue Jan 7, 2021 · 6 comments · May be fixed by #9

Comments

@byyoungjin
Copy link

byyoungjin commented Jan 7, 2021

@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?

Then you will find the tracking and logging stops.

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?

Originally posted by @HYJ29 in #2 (comment)

@byyoungjin byyoungjin changed the title @byCedric Not working on android simulator and real device in sleep mode. (related issue #2 ) Jan 7, 2021
@byyoungjin
Copy link
Author

byyoungjin commented Jan 25, 2021

@byCedric
Finally, I found a solution. I want to share it with you and hear your opinion. I want to be convinced that there is no problem with it.

Problem

The problem was after some minutes phone enters sleep mode, It stops logging ( on timeInterval 1000ms )
I thought it was the termination of tasks, but it was not.
If I reactive phone after the logging stops, The TaskManager gives me an array of locations it tracked, but not logged.
for example, If the log stops around 10 seconds, it gives 10 location object on locations array.

So for ideally, it should have no problem on the code and should work right.
But for some reason, if I have too much item to iterate to 'addLocation',
the number of locations that TaskManager give me increase by one every second
So I mean, if I reactive phone after 40seconds since it stops logging,
TaskManger give me 40 locations array at first, but 41 locations after once second, 42 locations after 2 second.. so on
that was the reason why logging goes crazy after reactivating the phone.

Solutions

So I fixed it to not iterate, but just dump in the whole locations array like this
const newLocations = [...existingLocations, ...locations ]

I didn't check that the locations object is exactly the locations that the phone tracked, but I think it would be, I'll test it soon.

I will request PR about this.
It would be really appreciated for me If you look into it and answer me.

Thank you!

@byyoungjin byyoungjin linked a pull request Jan 25, 2021 that will close this issue
@byyoungjin
Copy link
Author

byyoungjin commented Apr 11, 2021

@byCedric
I could fix the original issue with the above workaround.
but I still have an issue. I'm not working on it right now. But want to share with you.
this is my published app to the google play store for an internal test. (ios works well)
I run it with android galaxy 8, android version 9.

I actually used my app to track my running, I ran about 3km, around 20min, while my phone in sleep mode.

I think the arrays, android giving to me while on sleep mode are not accurate. And I need to look into it.

as you see below, there are some duplicated points recorded.

I also recorded with 'Strava'(a popular app for running tracking ). We can see the difference comparing with it.

@vasildimitroffhristoff
Copy link

@HYJ29 Some nasty fluctuating points appear especially with Android. Have you tried any filtering of the noisy data such as Kalman filter?

@byyoungjin
Copy link
Author

@vasildimitroffhristoff No, I have not. I don't have much knowledge of filtering raw data. Do you think it would be the solution~?

@vasildimitroffhristoff
Copy link

@HYJ29 we found out that the array with the locations coming from the background task after the device is awaken from sleep are in messed up order. Try sorting them by timestamp. I think it will fix some of the issues with the strange lines appearing on your track.

@byyoungjin
Copy link
Author

@vasildimitroffhristoff Thank you for letting me know! I'll try that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants