tags:

views:

96

answers:

1

Hello

I am struggling a bit with the LocationListener in Android. I want to make an app that will get the current GPS location, and then afterwards sleep for a long time. A day or more. In this period of time i want the GPS notification icon to not show.

What i have now, is in the onLocationChanged a Thread.sleep(x) but this will keep the icon on in the sleep period. How can i do this, and is there a better approach than to use Thread.sleep?

Thanks in advance

A: 

Hey Andreas! You have to turn off the LocationManager completly for that. I did it in my App, where I only check the Location every 10 seconds, 'cause I found out, that the turning off saves a bit more battery power than a min_distance or min_time of the LocationManager.

Something like:

// Turning off
mLocationManager.removeUpdates(gpsListener);
mLocationManager = null;

// Turning on again
mLocationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);            
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, GPS_MINTIME, GPS_MINDISTANCE, gpsListener);

The icon will disappear till the LocationManager is turned on again.

Keenora Fluffball
Hey FluffballYeah i finally figured it out, did it exactly the way you describe. I also learned that Thread.sleep is bad. Read about the Handler class and how to delay tasks. This turned out horrible since i ended up with recursive functions. And since i have a variable delay, i could not use the repeat-method. I finally stuck with the alarm manager, and it works like a charm.Thanks for your reply :)
Andreas