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 状态栏通知Notification
- android 通知Notification的使用小实例(振动,灯光,声音)
- Android 本地推送消息到通知栏 NotificationManager 、注册Andro
- 拦截短信,不让系统发通知
- Android Wear Preview- 归档通知(Stacking Notifications)
- android:versionCode和android:versionName 用途(转) App自动更