Android清理后台所有历史App任务
\frameworks\base\packages\SystemUI\src\com\android\systemui\recent\RecentsPanelView.java
public voiddeleteAllRecent(){
final ActivityManager am = (ActivityManager)
mContext.getSystemService(Context.ACTIVITY_SERVICE);
if (am != null) {
for(TaskDescription recent :mRecentTaskDescriptions){
am.removeTask(recent.persistentTaskId,ActivityManager.REMOVE_TASK_KILL_PROCESS);
}
}
if(mRecentTaskDescriptions!=null){
mRecentTaskDescriptions.clear();
if (mRecentTasksLoader.getLoadedTasks() !=null){
mRecentTasksLoader.getLoadedTasks().clear();
}
dismissAndGoBack();
}
}
public static void delAllRecentTask(Contextcontext){
Log.i("zhangliang=>1","delAllRecentTask");
final ActivityManager am =(ActivityManager)
context.getSystemService(Context.ACTIVITY_SERVICE);
if(mRecentTaskDescriptions==null){
mRecentTaskDescriptions = new ArrayList
mRecentTaskDescriptions=getTaskInRecentList(context);
}
for(TaskDescription recent :mRecentTaskDescriptions){
if(!recent.packageName.toString().equals("com.snowfish.aios.launcher")&&!recent.packageName.toString().equals("com.jeejen.family")){
am.removeTask(recent.persistentTaskId,ActivityManager.REMOVE_TASK_KILL_PROCESS);
}
}
if(mRecentTaskDescriptions!=null){
mRecentTaskDescriptions.clear();
if(RecentTasksLoader.getInstance(context).getLoadedTasks()!= null){
RecentTasksLoader.getInstance(context).getLoadedTasks().clear();
}
}
// dismissActivityGoBack(context);
}
//自定一个一个广播通知去清除所有的Task
frameworks\base\packages\SystemUI\src\com\android\systemui\recent\DeleteTaskReceiver.java
public classDeleteTaskReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context,Intent intent) {
if("CLEAR_ALL_TASK".equals(intent.getAction())){
RecentsPanelView.delAllRecentTask(context);
}
通过发送上面那个广播过去即可
更多相关文章
- android全屏显示
- Android(安卓)禁止转屏的方法
- android中广播接收者BroadcastReceiver
- 【Android开发】Toolbar与标题居中
- Android(安卓)融云SDK 集成
- 另一个更简单的Android应用程序全屏的方法
- 另一个更简单的Android应用程序全屏的方法
- Android(安卓)BroadcastReceiver 简介
- android Standard Broadcast Actions 的对比和锁屏前后的测试