gpt4 book ai didi

android - 为什么 getRunningTasks 没有将 RecentApplicationsActivity 识别为正在运行的任务?

转载 作者:行者123 更新时间:2023-11-29 00:20:23 25 4
gpt4 key购买 nike

ActivityManager am = (ActivityManager)this.getSystemService(Activity.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(5);

这是我的主屏幕应用程序中用于获取正在运行的 Activity 的代码。

当长按 HOME 键时,会出现最近使用的应用程序列表(带有名为 RecentApplicationsActivity 的 Activity)。但它没有被列在上面代码的“任务”中。

为什么这行不通?

最佳答案

因为它不是一个 Activity 而是一个显示最近应用程序的对话框。它称为 RecentApplicationsDialog。您可以查看 AOSP 中的代码。

https://android.googlesource.com/platform/frameworks/base/+/kitkat-release/policy/src/com/android/internal/policy/impl/RecentApplicationsDialog.java

此对话框由 WindowManagerService 管理的 PhoneWindowManager 处理。

https://android.googlesource.com/platform/frameworks/base/+/kitkat-release/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java

private void handleLongPressOnHome() {

if (mLongPressOnHomeBehavior < 0) {
mLongPressOnHomeBehavior
= mContext.getResources().getInteger(R.integer.config_longPressOnHomeBehavior);
if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
mLongPressOnHomeBehavior > LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
}
}

if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS);

// Eat the longpress so it won't dismiss the recent apps dialog when
// the user lets go of the home key
mHomeLongPressed = true;
}

if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_DIALOG) {
showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS);
} else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
try {
IStatusBarService statusbar = getStatusBarService();
if (statusbar != null) {
statusbar.toggleRecentApps();
}
} catch (RemoteException e) {
Slog.e(TAG, "RemoteException when showing recent apps", e);
// re-acquire status bar service next time it is needed.
mStatusBarService = null;
}
}
}

用来显示这个Dialog的Context不属于任何普通任务,而是使用系统上下文来显示这个Dialog。

关于android - 为什么 getRunningTasks 没有将 RecentApplicationsActivity 识别为正在运行的任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23562953/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com