Android的监听应用程序启动 [英] android listen for app launch

查看:382
本文介绍了Android的监听应用程序启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要制定哪些监听每个活动启动服务。 我必须做这样的事?

I need to develop a service which listen for every activity start. Must I do something like this?

ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> runningAppProcessInfo = am.getRunningAppProcesses();
for (int i = 0; i < runningAppProcessInfo.size(); i++) {
    Log.v("Proc: ", runningAppProcessInfo.get(i).processName);
}

和我需要做的每X秒?这是否会影响电池的消耗?

And do I need to do it every X seconds? Does it affect battery consumption?

推荐答案

据我所知,目前还没有办法听一个应用程序的推出,除非是第一次,它将推出。 <一href="http://developer.android.com/reference/android/content/Intent.html#ACTION_PACKAGE_FIRST_LAUNCH"相对=nofollow> ACTION_PACKAGE_FIRST_LAUNCH (广播事件:发送给当应用程序首次启动(这是它第一次被移出停止状态的)应用程序的安装程序包

As far as I know there is currently no way to listen to an app's launch, Unless it is the first time that it is launching. ACTION_PACKAGE_FIRST_LAUNCH (Broadcast Action: Sent to the installer package of an application when that application is first launched (that is the first time it is moved out of the stopped state).

所以我想您的解决方案是最适合这个权利了。

So I guess your solution is the best for this right now.

这篇关于Android的监听应用程序启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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