我想获得前台活动运行。而我能够得到这个信息,通过使用活动管理器通过以下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.
以下是问题
当活动A开始高于code给我topActivity = A 在接我一招,从活动A到B及以上code给我topActivity = B 然后我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
}
}
点击此处这里 了解更多信息。
Click here and here for more information.