如何找到在机器人当前的前景活动 [英] How to find the current foreground activity in android
问题描述
是否有可能在android.I当前的前景活动我不使用的ActivityGroup找到。
Is it possible to find the current foreground activity in android.I am not using ActivityGroup.
推荐答案
我的猜测是,你需要看的 ActivityManager类。我参加了一个简单的介绍一下该文档,这就是我想出了。
My guess is that it you need to look at the ActivityManager class. I took a brief look at the docs and this is what I came up with.
还有一个功能:
public List<ActivityManager.RunningTaskInfo> getRunningTasks (int maxNum)
在<一个href="http://developer.android.com/reference/android/app/ActivityManager.html#getRunningTasks%28int%29">Android文档:
之后才能返回当前正在运行的任务列表,与最近的是第一和旧的。需要注意的是跑并不意味着任何任务的code当前加载或活动 - 任务可能已被冻结的系统,以便它可以重新启动在previous状态时,旁边带到前台。
Return a list of the tasks that are currently running, with the most recent being first and older ones after in order. Note that "running" does not mean any of the task's code is currently loaded or activity -- the task may have been frozen by the system, so that it can be restarted in its previous state when next brought to the foreground.
我的想法是,如果你传递 MAXNUM = 1
,它应该给你最新的任务是运行的,即。的首要任务。每个 ActivityManager.RunningTaskInfo
有一个叫做财产 topActivity
。
My thought would be if you pass in maxNum=1
, it should give you the most recent task that was run, ie. the top task. Each ActivityManager.RunningTaskInfo
has a property called topActivity
.
public ComponentName topActivity
在<一个href="http://developer.android.com/reference/android/app/ActivityManager.RunningTaskInfo.html#topActivity">Android文档:活性成分在任务的历史堆栈的顶部。这是用户目前正在做。
From the Android docs: The activity component at the top of the history stack of the task. This is what the user is currently doing.
这篇关于如何找到在机器人当前的前景活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!