SystemUI中,Home键调出小刷子杀最近任务,整个流程从其RecentsPanelView.java开始:

View Codepublic void handleSwipe(View view) {
...
// Currently, either direction means the same thing, so ignore direction and remove// the task.final ActivityManager am = (ActivityManager)getContext().getSystemService(Context.ACTIVITY_SERVICE);if (am != null) {am.removeTask(ad.persistentTaskId, ActivityManager.REMOVE_TASK_KILL_PROCESS);①// Accessibility feedbacksetContentDescription(getContext().getString(R.string.accessibility_recents_item_dismissed, ad.getLabel()));sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);setContentDescription(null);}
}

ActivityManagerService.java

View Codeprivate void cleanUpRemovedTaskLocked(TaskRecord tr, int flags) {mRecentTasks.remove(tr);tr.removedFromRecents(mTaskPersister);final boolean killProcesses = (flags&ActivityManager.REMOVE_TASK_KILL_PROCESS) != 0;Intent baseIntent = new Intent(tr.intent != null ? tr.intent : tr.affinityIntent);ComponentName component = baseIntent.getComponent();if (component == null) {Slog.w(TAG, "Now component for base intent of task: " + tr);return;}// Find any running services associated with this app.mServices.cleanUpRemovedTaskLocked(tr, component, baseIntent);④if (killProcesses) {// Find any running processes associated with this app.final String pkg = component.getPackageName();ArrayList<ProcessRecord> procs = new ArrayList<ProcessRecord>();ArrayMap<String, SparseArray<ProcessRecord>> pmap = mProcessNames.getMap();for (int i=0; i<pmap.size(); i++) {SparseArray<ProcessRecord> uids = pmap.valueAt(i);for (int j=0; j<uids.size(); j++) {ProcessRecord proc = uids.valueAt(j);if (proc.userId != tr.userId) {continue;}if (!proc.pkgList.containsKey(pkg)) {continue;}procs.add(proc);}}// Kill the running processes.for (int i=0; i<procs.size(); i++) {ProcessRecord pr = procs.get(i);if (pr == mHomeProcess) {// Don't kill the home process along with tasks from the same package.continue;}if (pr.setSchedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE) {pr.kill("remove task", true);} else {pr.waitingToKill = "remove task";}}}}
/*** Removes the task with the specified task id.** @param taskId Identifier of the task to be removed.* @param flags Additional operational flags.  May be 0 or* {@link ActivityManager#REMOVE_TASK_KILL_PROCESS}.* @return Returns true if the given task was found and removed.*/private boolean removeTaskByIdLocked(int taskId, int flags) {TaskRecord tr = recentTaskForIdLocked(taskId);if (tr != null) {tr.removeTaskActivitiesLocked();cleanUpRemovedTaskLocked(tr, flags);③if (tr.isPersistable) {notifyTaskPersisterLocked(null, true);}return true;}return false;}@Overridepublic boolean removeTask(int taskId, int flags) {synchronized (this) {enforceCallingPermission(android.Manifest.permission.REMOVE_TASKS,"removeTask()");long ident = Binder.clearCallingIdentity();try {return removeTaskByIdLocked(taskId, flags);②} finally {Binder.restoreCallingIdentity(ident);}}}

ActiveServices.java:

View Codevoid cleanUpRemovedTaskLocked(TaskRecord tr, ComponentName component, Intent baseIntent) {ArrayList<ServiceRecord> services = new ArrayList<ServiceRecord>();ArrayMap<ComponentName, ServiceRecord> alls = getServices(tr.userId);for (int i=0; i<alls.size(); i++) {ServiceRecord sr = alls.valueAt(i);if (sr.packageName.equals(component.getPackageName())) {services.add(sr);}}// Take care of any running services associated with the app.for (int i=0; i<services.size(); i++) {ServiceRecord sr = services.get(i);if (sr.startRequested) {if ((sr.serviceInfo.flags&ServiceInfo.FLAG_STOP_WITH_TASK) != 0) {Slog.i(TAG, "Stopping service " + sr.shortName + ": remove task");stopServiceLocked(sr);} else {sr.pendingStarts.add(new ServiceRecord.StartItem(sr, true,sr.makeNextStartId(), baseIntent, null));if (sr.app != null && sr.app.thread != null) {// We always run in the foreground, since this is called as// part of the "remove task" UI operation.sendServiceArgsLocked(sr, true, false);}}}}}

TaskRecord.java:

View Code/*** Completely remove all activities associated with an existing* task starting at a specified index.*/final void performClearTaskAtIndexLocked(int activityNdx) {int numActivities = mActivities.size();for ( ; activityNdx < numActivities; ++activityNdx) {final ActivityRecord r = mActivities.get(activityNdx);if (r.finishing) {continue;}if (stack == null) {// Task was restored from persistent storage.r.takeFromHistory();mActivities.remove(activityNdx);--activityNdx;--numActivities;} else if (stack.finishActivityLocked(r, Activity.RESULT_CANCELED, null, "clear",false)) {--activityNdx;--numActivities;}}}/*** Completely remove all activities associated with an existing task.*/final void performClearTaskLocked() {mReuseTask = true;performClearTaskAtIndexLocked(0);mReuseTask = false;}

Process.java:

View Code/*** Background thread group - All threads in* this group are scheduled with a reduced share of the CPU.* Value is same as constant SP_BACKGROUND of enum SchedPolicy.* FIXME rename to THREAD_GROUP_BACKGROUND.* @hide*/public static final int THREAD_GROUP_BG_NONINTERACTIVE = 0;

转载于:https://www.cnblogs.com/fanfeng/p/4082815.html

removeTask相关推荐

  1. Android OkHttp框架解析

    Okhttp是由Sqare公司开发的开源网络访问库,是目前比较火的网络框架, 它处理了很多网络疑难杂症:会从很多常用的连接问题中自动恢复.如果你的服务器配置了多个IP地址,当第一个IP连接失败的时候, ...

  2. Java:定时启动线程

    参考:http://zhangjunhd.blog.51cto.com/113473/74646     http://www.cnblogs.com/jobs/archive/2007/04/27/ ...

  3. ActivityManager

    android.app.ActivityManager 这个类主要用来管理全部设备上的Activities. 权限:android.permission.GET_TASKS 方法:| 返回类型     ...

  4. netty reactor线程模型分析

    netty4线程模型 ServerBootstrap http示例 // Configure the server.EventLoopGroup bossGroup = new EpollEventL ...

  5. Netty系列(三):说说NioEventLoop

    前言 本来想先写下NioServerSocketChannel以及NioSocketChannel的注册流程的,但是最后发现始终离不开NioEventLoop这个类,所以在这之前必须得先讲解下NioE ...

  6. 阿里云自定义监控tomcat进程数

    阿里云提供自定义监控SDK,这有助于我们定制化的根据自身业务来做监控,下面我就根据业务需求来介绍一个简单的自定义监控配置. 阿里提供了2个版本的自定义监控接口: 自定义监控SDK(python版) : ...

  7. Netty防止内存泄漏措施

    谨以此文献给李林锋即将新生的爱女. 1.  背景 1.1 直播平台内存泄漏问题 某直播平台,一些网红的直播间在业务高峰期,会有 10W+ 的粉丝接入,如果瞬间发生大量客户端连接掉线.或者一些客户端网络 ...

  8. NioEventLoop启动流程源码解析

    NioEventLoop的启动时机是在服务端的NioServerSocketChannel中的ServerSocketChannel初始化完成,且注册在NioEventLoop后执行的, 下一步就是去 ...

  9. java中延迟任务的处理方式

    1.利用延迟队列 延时队列,第一他是个队列,所以具有对列功能第二就是延时,这就是延时对列,功能也就是将任务放在该延时对列中,只有到了延时时刻才能从该延时对列中获取任务否则获取不到-- 应用场景比较多, ...

最新文章

  1. Selenium VS QTP
  2. 套接字没有连接并且没有提供地址_网络是怎样连接的 -- web服务器接到请求后将会做什么...
  3. 【转载】[OS X笔记]安装MacPorts
  4. bzoj2957:楼房重建
  5. leetcode 1438. 绝对差不超过限制的最长连续子数组(滑动窗口+treemap)
  6. mysql添加分区健_MySQL添加分区添加索引
  7. Web Hacking 101 中文版 二十、漏洞报告
  8. 什么是计算机考试题,计算机考试word什么版本 计算机word考试试题
  9. 宿华、程一笑上市演讲:上市是接受更大机遇和挑战的新起点
  10. 免费RDP报表工具试用感受
  11. Ubuntu18.04安装有道词典
  12. TensorFlow中相关的维度处理函数
  13. 第一届广西英招杯部分WP
  14. Dev C++ 运行出现:源文件未编译
  15. window7旗舰版SP1官方原版自激活镜像iso
  16. 微型计算机原理与应用教材,微型计算机原理与应用(第3版)(普通高等教育十二五规划教材)...
  17. C语言程序设计(第三版)何钦铭著 习题3-5
  18. 神经网络 mse一直不变_卷积神经网络中十大拍案叫绝的操作
  19. CG CTF 南邮CTF SQL注入2
  20. java日历打印出的格式不对_Java打印某年某月的日历 没有错误但是运行出的月份与实际不符 求大神指导...

热门文章

  1. 回文数、罗马数转整数、整数反转
  2. 热点效应是指_热电偶的热电效应是什么意思 浅谈热电偶下的热点效应
  3. 本地缓存需要高时效性怎么办_详解微信小程序缓存--缓存时效性
  4. anaconda 怎么安装xlrd_Anaconda 安装 tensorflow 和 keras
  5. Pow(x, n)Python解法
  6. 最大子数组和Python解法
  7. go语言第一个程序-hello world
  8. 华东政法大学教学管理系统_中国科学技术大学1022万采购3包生命科学仪器
  9. jupyternotebook运行python_怎么运行jupyter notebook?
  10. java中堆与栈的区别_java中堆和栈的区别分析