Gps - Android-Best way to get new location in onResume

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

The app Im working on uses gps and sometimes in the onResume when the user restarts the app the location used is very old and sometimes very far away. It also will not update even when I have set the time to 0 in my location manager. Ive tried adding new listeners using both coarse and fine and switching from one to the other but I still cant get it to be reliable. Can some one point out to me what the best most reliable way to force a new location update in the onResume method. I no longer want to rely on lastLocationKnown as that is my problem now.

Edit: Maybe what I should have asked is how do I get a location that is constatly updated. It seems like you can only set your location as lastKnown which is giving me problems.

Answers

I had a similar problem, and realised that onProviderEnabled() is not immediately called onResume(). I ended up not unregstering my listeners in onPause(), but instead unregistered them in onDestroy().

Here is the link to the relevant documentation: http://developer.android.com/reference/android/location/LocationListener.html http://developer.android.com/reference/android/location/LocationListener.html

Here is the link to my original Stack Overflow question:
http://stackoverflow.com/questions/7508173/why-isnt-androids-onproviderenabled-method-being-called http://stackoverflow.com/questions/7508173/why-isnt-androids-onproviderenabled-method-being-called

Hope this helps. Mel

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/9051160/android-best-way-to-get-new-location-in-onresume

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils