时通知应用程序涉及到前台 [英] Notify when application comes to foreground

查看:159
本文介绍了时通知应用程序涉及到前台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有具有监视哪个应用程序是在前台和基于所述应用程序的服务做一些功能。

I have a service which has to monitor which application is in the foreground and based on the application do some functionality.

我可以得到的前台应用程序的列表,使用ActivityManager.getRunningAppProcesses()。
但有了这个我无法监控时,前台应用程序的变化。

I can get the list of foreground applications, using ActivityManager.getRunningAppProcesses(). But with this I cannot monitor when the foreground application changes.

恩。当这是前台应用程序1变为背景和新的应用程序2来到前台,服务应该收到通知。

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.

是否有广播在Android中发生的事情,让自己的服务可以注册到什么时候就在前台应用程序的改变,服务得到了通知,并根据需要可以做到的功能。

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

推荐答案

然后一个简单的解决方案是创建一个类型的静态变量在一些类和所有<上下文() code> onResume()活动的方法与实例初始化它..并且使用检查服务如果conditon 并进行..

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

这篇关于时通知应用程序涉及到前台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆