开发者

Android detect if an activity is on the top of the history stack

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 开发者_如何学Gobut not when an activity launches a new activity and thus calls its own onPause. Any ideas would be great.

Thanks


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.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜