How to handle that the application is minimized by HOME button

Plamen Nikolov picture Plamen Nikolov · Feb 17, 2011 · Viewed 12.3k times · Source

An issue has appeared a few days ago. I have an application that listen for GPS location. The listener is a background service that works all the time, this service saves data in application level and each activity reads this data. So, when i press back button i am able to catch this event and i can stop the service, but when i press HOME button the service is still working although the application is in background mode and this consumes battery, because the GPS always works. How can i handle this event? I do want to stop all services when the user presses HOME button and start them again when user gets back. 10x

Answer

Al Sutton picture Al Sutton · Feb 17, 2011

It sounds like you're catching the back button either via an onKey... method or in onStop. You should place your code in the onPause() method to ensure it's used whenever the app gets backgrounded.