获取当前可见的活动用户 [英] Get current visible activity to user

查看:125
本文介绍了获取当前可见的活动用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得前台活动运行。而我能够得到这个信息,通过使用活动管理器通过以下code。

I want to get the foreground activity running. And I am able to get this information by using activity manager by using following code.

activityManager = (ActivityManager) FWCommon.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
runningTaskInfoList = activityManager.getRunningTasks(1);
componentName = runningTaskInfoList.get(0).topActivity;

假设我有两个活动A和B以及我称之为高于code从onResume两个活动A的()和B。

Suppose I have two activities A and B and i call this above code from onResume() of both activities A and B.

以下是问题

  1. 当活动A开始高于code给我topActivity = A
  2. 在接我一招,从活动A到B及以上code给我topActivity = B
  3. 然后我preSS回到从b活动回迁及以上code再次给我topActivity = B,而不是一个。

THX Dalvin

Thx Dalvin

推荐答案

尝试使用getRunningAppProcesses()来获得RunningAppProcessInfo列表。然后通过每个RunningAppProcessInfo,并检查它是否在前台做这样的:

Try using getRunningAppProcesses() to get a list of RunningAppProcessInfo. Then go through each RunningAppProcessInfo and check if it is in the foreground by doing this:

List<ActivityManager.RunningAppProcessInfo> processes = manager.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo process : processes)
{
    // Take a look at the IMPORTANCE_VISIBLE property as well in the link provided at the bottom
    if (process.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND)
    {
        // Put code here
    }
}

点击<一href="http://developer.android.com/reference/android/app/ActivityManager.html#getRunningAppProcesses%28%29"相对=nofollow>此处这里 了解更多信息。

Click here and here for more information.

这篇关于获取当前可见的活动用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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