Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lock screen doesn't cause onStop() to get called

Tags:

android

My app uses GPS, so I remove GPS updates in onStop() so it doesn't use up battery when it shouldn't. However, I noticed that the battery on my test phone was running down if my app was open when the lock screen comes on.

So to test it, I added a Log.i(...) to the onStop() method of my activity. Sure enough, onStop() does not get called when I press the off button on my HTC Incredible (which turns off the screen).

Is there any way to listen for the lock screen, or the screen turning off, since it doesn't call onStop() like it should?

Thanks.

like image 933
Tenfour04 Avatar asked Dec 28 '22 02:12

Tenfour04


1 Answers

onStop is not guaranteed to be called, onPause is. Use onPause to remove GPS updates from eating battery.

like image 65
the100rabh Avatar answered Jan 31 '23 21:01

the100rabh