开发者

Notify when application comes to foreground

开发者 https://www.devze.com 2023-03-13 21:03 出处:网络
I have a service which has to monitor which application is in the foreground and based on the application do some functionality.

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.

I do not want to do any changes in the Applications... Any possibilities please suggest...


Then a simple solution is Create static variable of type Context() in some Class and in all onResume() methods activities initialize it with their Instances.. and check it in service using if conditon and carry on..

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号