UMAR-MOBITSOLUTIONS
UMAR-MOBITSOLUTIONS

Reputation: 78004

How to stop GPS Updates in android when application is idle?

friends,

i have created an application in which i am getting GPS location onCreate Method and

onPause method i remove Location updates.

after taking gps update i left my mobile idle and whole night it was in idle mode and my application was running in it, in the morning bettery was down due to GPS i guess.

any one guide me how to handle this situation in which method should i stop using GPS if application is idle other than onPause()?

any help would be appreciated.

Upvotes: 0

Views: 3074

Answers (3)

GPSmaster
GPSmaster

Reputation: 914

I asked a similar question about timing out the GPS if the user moves indoors where a signal cannot be found. I started a timer within the LocationListener class and remove updates if a signal isn't found within 5-8 seconds. There's some code here that might help How to time out GPS signal acquisition

Upvotes: 1

MByD
MByD

Reputation: 137442

Stop the location update notification in onPause() is fine, but please note two things.

  1. If GPS is still on, it will still eat your battery.
  2. According to the activity life cycle if you start listening to location updates in onCreate() and stop it in onPause(), then when you return your application to foreground it will not register to updates again, consider moving the registration to onResume().

Upvotes: 1

Moystard
Moystard

Reputation: 1837

If you stop receiving broadcasts (thus unregistering your BroadcastReceiver in the onPause() method of your activity), there is no reason why your application would keep receiving updates from the LocationManager.

Upvotes: 0

Related Questions