我想让前台活动正常运行。我可以通过使用以下代码使用活动管理器来获取此信息。
activityManager = (ActivityManager) FWCommon.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
runningTaskInfoList = activityManager.getRunningTasks(1);
componentName = runningTaskInfoList.get(0).topActivity;
假设我有两个活动A和B,我从活动A和B的onResume()调用上面的代码。
以下是问题
THX Dalvin
答案 0 :(得分:9)
尝试使用getRunningAppProcesses()获取RunningAppProcessInfo列表。然后通过执行以下操作遍历每个RunningAppProcessInfo并检查它是否在前台:
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
}
}