It has been asked before but never got an answer: I want to know when a certain 3rd party activity (the browser) is in the foreground and when it is not in the foreground anymore. I know how to check which activity is in the foreground, but how do I listen to changes in the activity stack.
Any other idea is welcome.
There aren't any events broadcast that you could listen for. The only way to do this would be to continuously monitor the foreground task using
ActivityManager.getRunningTasks()
and check for changes intopActivity
in the foreground task.