I want to detect when my application is sent to the background. There are many questions about hooking the HOME key - I understand this is possible only by registering as a launcher app.
...BUT... as always there is a client who wants certain behaviour...
We have an app with high security requirements. The client wants the app to log out of the server whenever the app goes into the background for whatever reason (phone call, HOME key, back on last activity) (* *to clarify I mean that when the front Activity on the screen is not one of my app's activities **).
So, if I can't hook the HOME key, what other options are there? Obviously just hooking onPause()
won't help, because that is Activity
-specific.
The "best" we have come up with is to keep an array of Activity references in our Application class. In each Activity's onResume()
we add it to this array. In onPause()
we remove it. Also in onPause()
we enumerate through this array to find out if any of the registered activities are in the foreground. If no foreground activity is found, user gets logged out.
I am unhappy with this as a solution, and hope to find a better way.