0

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.

UMAR-MOBITSOLUTIONS
  • 77,236
  • 95
  • 209
  • 278
  • Did you confirm with settings - battery use that your application was in fact using GPS for that many hours? – Josh Lee May 05 '11 at 17:04
  • does android logs such kind of information which application consumed more battery? if yes then how to check it please guide bit more.. – UMAR-MOBITSOLUTIONS May 05 '11 at 19:04
  • 1
    It’s under *Settings / About phone / Battery use / app name*. It’s broken down by CPU usage, data sent, GPS usage, etc. – Josh Lee May 05 '11 at 19:16
  • jleedev is right. You should check what application is burning the battery and if it's the GPS or the CPU that's responsible. – GPSmaster May 06 '11 at 07:32

3 Answers3

1

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().
MByD
  • 135,866
  • 28
  • 264
  • 277
  • if phone is in idle state do you think it will call onPause method of that activity? according to your point 1 can phone GPs stays on if onPause is still there? – UMAR-MOBITSOLUTIONS May 05 '11 at 19:06
1

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

Community
  • 1
  • 1
GPSmaster
  • 844
  • 3
  • 15
  • 31
0

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.

Moystard
  • 1,827
  • 2
  • 17
  • 18