2

This is the question about the activity life-cycle vs. location updates. From what I read, I should register location updates in OnResume and remove location updates in OnPause of my activities. But, my app shows your current speed in real time (location updates set to 1 second and 0 meters) and has several activities - home screen, some list, settings screen, etc.

If I use OnPause or OnStop for remove location updates and OnResume to get them back again, and user just goes to another screen and then back to home, there is significant lag in receiving data and speed cannot be shown. Is there any way to distinguish between user going to another activity within my app, and leaving app - for the purpose of removing location updates?

I know about OnUserLeaveHint event, but no luck here - it is fired also when user is just going for settings screen and back.

rouen
  • 5,003
  • 2
  • 25
  • 48
  • Why not just get location updates in a background service? You can start the service when your app starts and end it when you close your app. – Dage Feb 24 '14 at 10:11
  • Actually I am doing this in service. But user shall have the option of disable background mode - so i need to know when to enable and disable location updates. So the question remains the same, I was just trying to keep it simple. How do you determine "when you close your app" in android? – rouen Feb 24 '14 at 10:14
  • http://stackoverflow.com/questions/3667022/android-is-application-running-in-background/5862048#5862048 – Dage Feb 24 '14 at 10:30
  • Thanks Dage, I know about this method, but it does not solve the lag problem - if I remove location updates in OnPause and request them back right one second later, there is few seconds lag before it goes live again. I am considering starting thread in OnPause which will sleep 3 seconds and then check if some other activity has OnResume-d in the meantime and remove location updates if not. But that seems sooo nasty – rouen Feb 24 '14 at 10:43
  • I'm not sure if you can do something about the lag, it takes a while for the location updates to start. GPS is pretty slow to start up again, network location might be faster, if you haven't already done so you should try to set it to network updates and see if the lag is still that much. I could be completely wrong tho.. – Dage Feb 24 '14 at 15:36

0 Answers0