Alexander
Alexander

Reputation: 646

Android Location based services

I am a beginner. I want to develop an application which can generate location based notifications. In android developer website I found in order to maintain a balance between battery life and data exchange one should consider

  1. frequency of new updates
  2. window in which you listen for location updates.

I know frequency can be controlled by calling requestLocationUpdates(). My question is how can I control the window in which I listen for updates ? Does it mean that once I acquire the location update from onLocationChanged() method of LocationListener class, I should stop listening for updates using removeUpdates() ??

Thanks

Upvotes: 1

Views: 667

Answers (2)

Luis
Luis

Reputation: 12048

GPS device only start working (and consuming power) when you register for requestLocationUpdates().

Teoretically the GPS can switch off between updates if they are not very frequent. Let's say for example that you have requested updates every 5 minutes, then the GPS can switch off for 4 minutes and 30 secounds aprox. and switch on in time to acquire the next location. If you set the new locations requests for every 5 secounds, GPS will not switch off between updates.

I have one application that keeps GPS awake full time, recording the locations in a database. This application can also show a map and draw the track recorded. My experience is that the power used to draw the map with track changing in real time is much higher then the power used by the GPS.

good luck

Upvotes: 1

Bianca Daniciuc
Bianca Daniciuc

Reputation: 930

I think you should stop listenting for updates only when you don't need anymore new locations. If you need only one new location, stop listenting right away is the best approach. For getting more locations(as the user moves) it's recommended to start listen for location updates in onResume and stop listenting in onPause. That means your onLocationChanged will be called only when your activity is in front of all others (is visible).

In conclusion, the activity that manages the window you need should have these calls as specified above.

Upvotes: 0

Related Questions