I have a service which has to monitor which application is in the foreground and based on the application do some functionality.
I can get the list of foreground applications, using ActivityManager.getRunningAppProcesses()
. But with this I cannot monitor when the foreground application changes.
ex. when Application 1 which was foreground goes to background and a new Application 2 comes to foreground, the service should be notified about this.
Are there any Broadcasting happening in Android, so that my service can register to that and when there is a change in foreground application, the service gets a notification and can do the functionality as required.