我正在写一个启动器,它需要从系统中清除最近的应用程序/任务列表,而不是"没有在最近的任务列表中显示我的应用程序",但我现在不知道它.我在stackoverflow中搜索过,只有这个问题匹配,但答案没有任何帮助.其他一些人问了同样的问题,他提到了Android 4.0的RemoveTask.是的,我已经检查了Android 2.3.7和Android 4.0的源代码,估计一轮,我想如果我可以删除在ActivityMangerService.Java中定义的mRecentTasks列表,我几乎可以达到终点:
final ArrayList<TaskRecord> mRecentTasks = new ArrayList<TaskRecord>();
Run Code Online (Sandbox Code Playgroud)
另一个可能有用的定义:
static ActivityManagerService mSelf;
public static ActivityManagerService self() {
return mSelf;
}
Run Code Online (Sandbox Code Playgroud)
因为我不熟悉Java和refelction,所以我需要有关清除此列表的方法的帮助,下面是我的代码:
public static <T> void clearRecentTaskList(Launcher launcher){
ActivityManager am = (ActivityManager) launcher.getSystemService(Context.ACTIVITY_SERVICE);
Object systemRecentTask = new ArrayList<T>();
Object receiver = null;
Field recentTaskList = null;
Class<?> service = null;
Field self = null;
try {
service = Class.forName("com.android.server.am.ActivityManagerService");
Log.d(LOG_TAG, "clearRecentTaskList, service gotton"+service.getName());
} catch (ClassNotFoundException e2) {
Log.d(LOG_TAG, "clearRecentTaskList, class service not found");
}
try { …
Run Code Online (Sandbox Code Playgroud)