2

我正在尝试从 android 的任务列表中启动最后一个最近的任务。使用 ActivityManager 获取任务列表。这会给我任务 id、baseintent 等 ActivityManager m = (ActivityManager)ChatHeadService.this.getSystemService(ACTIVITY_SERVICE); 列出最近的任务 = m.getRecentTasks(2, ActivityManager.RECENT_WITH_EXCLUDED);

这是我用来获取最后的代码。

但是当我运行它时它不会切换。

if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
                        final ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
                        am.moveTaskToFront(apps.id, ActivityManager.MOVE_TASK_WITH_HOME);
                    } else { // API 10 and below (Gingerbread on down)
                        Intent restartTaskIntent = new Intent(apps.baseIntent);
                        if (restartTaskIntent != null) {
                            restartTaskIntent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
                            try {
                                startActivity(restartTaskIntent);
                            } catch (ActivityNotFoundException e) {
                                Log.w("MyApp", "Unable to launch recent task", e);
                            }
                        }
                    }

这也不适合我。

我正在寻找这样的应用程序

4

0 回答 0