An android app that I'm writing seems to consume a lot of battery even when it's not the foreground application. My assumption is that I need to unregister the listeners for gps, orientation, etc., when the application is not in the foreground.
The thing is, I have a variety of different activities that I switch between and I don't want the listeners to be unregistered as long as I'm switching between them. However, if the user holds down home and switches to another app (or if a phonecall happens or whatever) I want my app to stop doing anything at all.
All the on* methods of an activity are specific to that activity. How do I listen for switching away from my application entirely?