1

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...

4

1 回答 1

0

然后一个简单的解决方案是在某个类中创建类型的静态变量,Context()并在所有onResume()方法中,活动用它们的实例初始化它......并在服务中使用if conditon并继续......

于 2011-06-17T12:21:30.390 回答