本文介绍了听ActivityManager事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

,才有可能以某种方式听ActivityManager,例如发生的事件当活动开始了吗?是否ActivityManager发送广播?我没有带发现任何表明它。

is it possible somehow to listen to the events of the ActivityManager, e.g. when activities are started? Does the ActivityManager send broadcasts? I havn't found anything indicating that it does.

我基本上需要做的:我想我的应用程序推出的我,每当某个(第三方)应用程序启动活动之一/需要关注。问题是这样的需要发生实际显示的第三方应用程序之前。

What I basically need to do: I want my app to launch one of my activities whenever a certain (thirdparty) app is launched/takes focus. Problem is this needs to happen before the thirdparty app is actually displayed.

我已经试过,只要解决方法:

What I have tried so far as workarounds:

  1. logcat的输出:我查询的logcat每0.8秒(过滤,只显示ActivityManager事件),但吃了很多ressources
  2. getRunningTasks:降低了电话了很多也和也不是很安全的,因为活动可能正在运行,但当前未在焦点

任何想法?谢谢!

基督教

推荐答案

我想,有没有其实其他传统的方法来处理glabal系统状态,只有

I suppose there is no actually other legacy way to handle glabal system state, only

 (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);

ActivityManager.getRecentTasks() - 返回当前正在运行的任务列表,与最近的是第一和旧的后,以

ActivityManager.getRecentTasks() - Return a list of the tasks that are currently running, with the most recent being first and older ones after in order.

有关详细信息,请检查文档

For details check docs

不过也许Android是一个Linux可以运行的系统工具,如

Perhaps though Android is a Linux you can run system tools like

Runtime.getRuntime().exec("ps -aux | grep smth")

不过,我认为这将是很难检测到特定的Java应用程序。

But I think it would be hard to detect particular java application.

这篇关于听ActivityManager事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-07 13:56