Friday, November 12, 2010

[android-developers] LocationListener and getLastKnownLocation

In one application, when an activity start I use the
getLastKnownLocation to get the last know position, using something
like:
Location
position=mlocManager.getLastKnownLocation(mlocManager.getBestProvider(new
Criteria(), true));
(in the onCreate)

After this, my application register a listener in the onResume() (and
removes it in the onPause()), something like:

protected void onPause() {
if(mlocManager!=null) mlocManager.removeUpdates(this);
super.onPause();
}

protected void onResume() {
if(mlocManager!=null)
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
60000, this);
super.onResume();
}

And it works ok, I get new position, the problem is that when I close
my application and after some time I restart it and I get the last
know location again it does not take any of the positions I got with
my application.
Why does the mobile does not store these position like the lastknow
positions?
do I have to do anythig more?

(if the problem is not clear this is the time sequence of an example)
Start app, getLastKnownLocation it's from 10:00 for example now it's
12:00
register listener, I got wifi or gps positions until 13:00
close the application, start again and getLastKnownLocation and I got
no position... why?

Regards. Gabi.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate