日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

removeTask

發布時間:2023/12/18 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 removeTask 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。