循环浏览最近在android中打开的应用程序

时间:2014-04-06 20:32:32

标签: android fast-app-switching android-recents

请帮我循环浏览最近在android中打开的应用程序,如果我有1,2,3,4,5现在我在3应用程序中,我想以同样的方式去我想要的2和1应用程序去4和5申请。

我已使用以下代码导航到下一个应用,但它没有按预期工作。

final Intent intent = new Intent(Intent.ACTION_MAIN);
                final ActivityManager am = (ActivityManager) mContext
                        .getSystemService(Context.ACTIVITY_SERVICE);
                String defaultHomePackage = "com.android.launcher";
                intent.addCategory(Intent.CATEGORY_HOME);
                final ResolveInfo res = mContext.getPackageManager().resolveActivity(intent, 0);
                if (res.activityInfo != null && !res.activityInfo.packageName.equals("android")) {
                    defaultHomePackage = res.activityInfo.packageName;
                }
                List <ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(5);
                // lets get enough tasks to find something to switch to
                // Note, we'll only get as many as the system currently has - up to 5
                while ((lastAppId == 0) && (looper < tasks.size())) {
                    packageName = tasks.get(looper).topActivity.getPackageName();
                    if (!packageName.equals(defaultHomePackage) && !packageName.equals("com.android.systemui")) {
                        lastAppId = tasks.get(looper).id;
                    }
                    looper++;
                }
                if (lastAppId != 0) {
                    am.moveTaskToFront(lastAppId, ActivityManager.MOVE_TASK_NO_USER_ACTION);
                } else {
                    Toast.makeText(mContext, mStrNoPrevApp, Toast.LENGTH_SHORT).show();
                }
            }

0 个答案:

没有答案