yayaa / LocationManager

Simplify getting user's location for Android
807 stars 187 forks source link

Stop onResume location updates #12

Closed dimkonomis closed 8 years ago

dimkonomis commented 8 years ago

Hello, great library for avoiding all Google Api client boilerplate code. Is there currently a way to stop onResume location updates?And if not, Is there a chance that you could add an option to disable that?

yayaa commented 8 years ago

Why do you need to do that? I mean, can you explain me the thing that you need, so that i might suggest some other ways.

But yeah, what you could do is basically create a Provider class which extends GPServicesLocationProvider (or other one, you know) and override onResume method then remove super.onResume call from there, so that it won't be trying to reconnect. Don't forget to set your provider to LocationManager.

Or if you need location just once, you can set keepTracking to false in configuration so it won't try to connect next time. (But with this one, if you didn't receive location before user leaves and come back, onResume will still be working... I would say this is what you need though, if it is not that critical not to use onResume)

dimkonomis commented 8 years ago

The scenario is simple and common. I fetch some data based on user's location and populate a recyclerview. The user clicks on a recyclerview's item and goes to detail screen. At the moment when the user clicks the back button, the data is been fetched again because of the location update on onResume and i want to avoid that.

I tried to set the keepTracking to false but still no luck.

yayaa commented 8 years ago

Ahhh, got it! Yes, that's a bug! Because even though you receive location and have keepTracing false onResume there is no control for that. I will fix it as soon as i got time, meanwhile if it is really urgent for you please feel free to create a PR :)

yayaa commented 8 years ago

@dimkonomis you can also do a workaround by; Create your own implementation of LocationBaseActivity (if you are using, of course) and in your onResume implementation check locationManager.isWaitingForLocation() before you call locationManager.onResume This should work for your case! I mean, for now, until i update the library

dimkonomis commented 8 years ago

Unfortunately, i've got no free time at the moment, so cant create a PR. Thanks for your help and for your quick responce, i'll check the workaround you suggested :)

yayaa commented 8 years ago

Fixed @dimkonomis you'll not receive any location after you get one and specified as keepTracking false, onResume activity. You can update library version 1.1.3 :)