removeTask
SystemUI中,Home键调出小刷子杀最近任务,整个流程从其RecentsPanelView.java开始:
public 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 feedback
setContentDescription(
getContext().getString(R.string.accessibility_recents_item_dismissed, ad.getLabel()));
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
setContentDescription(null);
}
}
private 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;
}
@Override
public 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);
}
}
}
void 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);
}
}
}
}
}
/**
* 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;
}
/**
* 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;
removeTask的更多相关文章
- Android线程管理之ThreadLocal理解及应用场景
前言: 最近在学习总结Android的动画效果,当学到Android属性动画的时候大致看了下源代码,里面的AnimationHandler存取使用了ThreadLocal,激起了我很大的好奇心以及兴趣 ...
- zone.js - 暴力之美
在ng2的开发过程中,Angular团队为我们带来了一个新的库 – zone.js.zone.js的设计灵感来源于Dart语言,它描述JavaScript执行过程的上下文,可以在异步任务之间进行持久性 ...
- C#定时任务组件之FluentScheduler
FluentScheduler是.NET开源处理定时任务组件 1.任务的创建注册 public static void TaskActionByMinutes(Action action, int c ...
- Android 中BaseActivty
Base接口 IBaseActivity package liu.basedemo.base; /** * 基类接口 * Created by 刘楠 on 2016/7/28 0028.23:05 * ...
- Android 中MyApplication
package liu.basedemo; import android.app.Activity; import android.app.Application; import java.lang. ...
- NHibernate实战详解(一)领域模型设计
关于NHibernate的资料本身就不多,中文的就更少了,好在有一些翻译文章含金量很高,另外NHibernate与Hibernate的使用方式可谓神似,所以也有不少经验可以去参考Hibernate. ...
- Android批量图片加载经典系列——采用二级缓存、异步加载网络图片
一.问题描述 Android应用中经常涉及从网络中加载大量图片,为提升加载速度和效率,减少网络流量都会采用二级缓存和异步加载机制,所谓二级缓存就是通过先从内存中获取.再从文件中获取,最后才会访问网络. ...
- android 后台附件下载
在service中通过在oncreat()中开启一个线程,轮训ArrayList<AttachmentTask> 我这个附件下载的任务list ,ArrayList<Attachme ...
- Netty源码阅读(一) ServerBootstrap启动
Netty源码阅读(一) ServerBootstrap启动 转自我的Github Netty是由JBOSS提供的一个java开源框架.Netty提供异步的.事件驱动的网络应用程序框架和工具,用以快速 ...
随机推荐
- 规划收发你的邮件,使用qq邮箱接收阿里云企业邮邮件
使用qq邮箱接收阿里企业邮 首先管理员开通企业邮后会发来激活短信 根据短信提示打开https://qiye.aliyun.com企业邮登陆地址 使用短信提供的密码登陆邮箱 首次登陆时会让我们重设密码 ...
- 网页Gzip
网页Gzip压缩检测工具 网站Gzip压缩可以减小服务器带宽占用,提高用户打开网页速度,最多可以提升网站80%的性能,是每个网站必须开启的功能, 站长工具网页 Gzip压缩检测工具方便站长朋友们检测特 ...
- SqlServer中的merge操作,相当地风骚
今天在一个存储过程中看见了merge这个关键字,第一个想法是,这个是配置管理中的概念吗,把相邻两次的更改合并到一起.后来在technet上搜索发现别有洞天,原来是另外一个sql关键字,t-sql的语法 ...
- Play - js/css concatenation & minify
1. Css We’ll use LESS CSS, all less sources are defined in the app/assets, and they will be compiled ...
- AIX filesystemcache引发的Oracle事故
链接地址: http://www.jydba.net/aix-filesystemcache%e5%bc%95%e5%8f%91%e7%9a%84oracle%e4%ba%8b%e6%95%85/ A ...
- 安装cocoaPod 的问题
APPLEdeiMac:cocoapod案例 apple$ pod install Analyzing dependencies [!] The dependency `Reachability (~ ...
- linux下安装svn(基于编码的方式)
svn是什么,相信能看到这里的同学应该不会有这个问题了,费话不多说,开始: 1.创建目录 mkdir /home/svn/ 2.获取安装svn所需源文件(svn的官方网址是http://subvers ...
- HDU3591找零,背包
题目大概的意思就是:小强用硬币买东西,硬币有N种,面值为Vi,店家有各种硬币都有无限个,而小强只有Ci个(分别对应Vi) 问最小交易硬币数,就是一个有找零的背包问题啦. 我的上一篇博客跟这hdu359 ...
- java设计模式——接口模式
java将接口的概念提升为独立的结构,体现了接口与实现分离.java接口允许多个类提供相同的功能,也允许一个同时实现多个接口.java的接口与抽象类十分相似.java与抽象类中的区别: 1.一个类可以 ...
- Gtest打桩函数
假设Client的定义如下 class Client { ...... public: virtual bool GetData(std::string& data); ...... }; 我 ...