user3616198
user3616198

Reputation: 31

Why does getRunningTasks does not identify RecentApplicationsActivity as a running task?

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

This is the code used in my home screen app to get the running activities.

When the HOME key is long pressed, the recently used app list (with an activity named RecentApplicationsActivity) comes up. but it's not being listed in "tasks" in the above code.

Why doesn't this work?

Upvotes: 2

Views: 643

Answers (1)

AJAY PRAKASH
AJAY PRAKASH

Reputation: 1110

Because its not an Activity but a Dialog which shows the RecentApplications. Its called RecentApplicationsDialog. You can check the code in AOSP.

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

This Dialog is handled by the PhoneWindowManager which is managed by WindowManagerService.

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;
            }
        }
    }

The Context used to show this Dialog does not belongs to any normal task, instead system context is used to show this Dialog.

Upvotes: 2

Related Questions