Categories
discuss

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

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 …

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.

Answer

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

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..