的Andr​​oid检测如果活动是关于历史堆栈的顶部 [英] Android detect if an activity is on the top of the history stack

查看:98
本文介绍了的Andr​​oid检测如果活动是关于历史堆栈的顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从父类的活动,反正是有弄清楚,如果孩子是在历史堆栈的顶部。我需要执行所有我在活动的onPause的作用,但前提是该活动的onPause运行,它是顶级的活动。如果用户点击Home键而不是当一个活动启动一个新的活动,从而调用它自己的onPause可能发生这种情况。任何想法将是巨大的。

From a parent class of an activity is there anyway to figure out if the child is on the top of the history stack. I need to perform an action on all of my activities in onPause, but only if the activity is running onPause and it is the top activity. This might happen if the user clicks the home button but not when an activity launches a new activity and thus calls its own onPause. Any ideas would be great.

感谢

推荐答案

借助 ActivityManager 包括一<一href=\"http://developer.android.com/reference/android/app/ActivityManager.html#getRunningTasks%28int%29\">getRunningTasks()方法,这将使你的所有当前活动的任务:为了以后返回当前正在运行的任务列表,最近的是第一和旧的。需要注意的是跑,并不意味着任何任务的$ C $的c当前加载或活性 - 任务可能已被系统冻结,以便它可以在它的previous状态被重新启动时,下一个赞助商前台

The ActivityManager includes a getRunningTasks() method that will give you all of the currently active tasks: 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.

返回的数据是<一个列表href=\"http://developer.android.com/reference/android/app/ActivityManager.RunningTaskInfo.html\">ActivityManager.RunningTaskInfo,每个包括组件名来获得它重新presents活动。

The data returned is a list of ActivityManager.RunningTaskInfo, each of which includes the ComponentName to derive the activity it represents.

这篇关于的Andr​​oid检测如果活动是关于历史堆栈的顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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