Android4.4 近期任务列表RecentsActivity与RecentTasksLoader

android4.4\frameworks\base\packages\SystemUI\src\com\android\systemui\recent\RecentsActivity.java

此函数是打开最近应用点击空闲地方跳转

public void dismissAndGoHome() {

if (mRecentsPanel != null) {

Intent homeIntent = new Intent(Intent.ACTION_MAIN, null);

homeIntent.addCategory(Intent.CATEGORY_HOME);

homeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK

| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

startActivityAsUser(homeIntent, new UserHandle(UserHandle.USER_CURRENT));//这里是跳转到系统最高Launch 里面

}

}

//记录最近应用在这里面

android4.4\frameworks\base\packages\SystemUI\src\com\android\systemui\recent\RecentTasksLoader.java

protected Void doInBackground(Void... params) {

// We load in two stages: first, we update progress with just the first screenful

// of items. Then, we update with the rest of the items

final int origPri = Process.getThreadPriority(Process.myTid());

Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);

final PackageManager pm = mContext.getPackageManager();

final ActivityManager am = (ActivityManager)

mContext.getSystemService(Context.ACTIVITY_SERVICE);

final List<ActivityManager.RecentTaskInfo> recentTasks =

am.getRecentTasks(MAX_TASKS, ActivityManager.RECENT_IGNORE_UNAVAILABLE);

int numTasks = recentTasks.size();

ActivityInfo homeInfo = new Intent(Intent.ACTION_MAIN)

.addCategory(Intent.CATEGORY_HOME).resolveActivityInfo(pm, 0);

boolean firstScreenful = true;

ArrayList<TaskDescription> tasks = new ArrayList<TaskDescription>();

// skip the first task - assume it‘s either the home screen or the current activity.

final int first = 0;

for (int i = first, index = 0; i < numTasks && (index < MAX_TASKS); ++i) {

if (isCancelled()) {

break;

}

final ActivityManager.RecentTaskInfo recentInfo = recentTasks.get(i);

Intent intent = new Intent(recentInfo.baseIntent);

if (recentInfo.origActivity != null) {

intent.setComponent(recentInfo.origActivity);

}

//关键代码

// Don‘t load the current home activity.

if (isCurrentHomeActivity(intent.getComponent(), homeInfo)) {//这里是屏蔽了系统最高launch 不记录在最近应用的栈中

continue;

}

// Don‘t load ourselves

if (intent.getComponent().getPackageName().equals(mContext.getPackageName())) {

continue;

}

TaskDescription item = createTaskDescription(recentInfo.id,

recentInfo.persistentId, recentInfo.baseIntent,

recentInfo.origActivity, recentInfo.description);

if (item != null) {

while (true) {

try {

tasksWaitingForThumbnails.put(item);

break;

} catch (InterruptedException e) {

}

}

tasks.add(item);

if (firstScreenful && tasks.size() == mNumTasksInFirstScreenful) {

publishProgress(tasks);

tasks = new ArrayList<TaskDescription>();

firstScreenful = false;

//break;

}

++index;

}

}

if (!isCancelled()) {

publishProgress(tasks);

if (firstScreenful) {

// always should publish two updates

publishProgress(new ArrayList<TaskDescription>());

}

}

while (true) {

try {

tasksWaitingForThumbnails.put(new TaskDescription());

break;

} catch (InterruptedException e) {

}

}

Process.setThreadPriority(origPri);

return null;

}

};

mTaskLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

loadThumbnailsAndIconsInBackground(tasksWaitingForThumbnails);

}

时间: 2024-09-12 10:00:04

Android4.4 近期任务列表RecentsActivity与RecentTasksLoader的相关文章

[深入理解Android卷二 全文-第六章]深入理解ActivityManagerService

由于<深入理解Android 卷一>和<深入理解Android卷二>不再出版,而知识的传播不应该因为纸质媒介的问题而中断,所以我将在CSDN博客中全文转发这两本书的全部内容 第6章 深入理解ActivityManagerService 本章主要内容: ·  详细分析ActivityManagerService 本章所涉及的源代码文件名及位置: ·  SystemServer.java frameworks/base/services/java/com/android/server/

Android Notification自定义通知样式你要知道的事

本文将根据个人经验对Notification做个总结,以供参考! 什么是通知(Notification) 通知是一个可以在应用程序正常的用户界面之外显示给用户的消息. 通知发出时,它首先出现在状态栏的通知区域中,用户打开通知抽屉可查看通知详情.通知区域和通知抽屉都是用户可以随时查看的系统控制区域. 作为安卓用户界面的重要组成部分,通知有自己的设计指南.在Android 5.0(API level 21)中引入的 Material Design 的变化是特别重要的,更多信息请阅读 通知设计指南.

Activity的启动流程分析

Activity是Android应用程序的四大组件之一,负责管理Android应用程序的用户界面,一般一个应用程序中包含很多个Activity,他们可能运行在一个进程中,也可能运行在不同的进程中. 我们主要通过启动在不同进程中的Activity,来分析Activity的启动流程及AMS对Activity的管理逻辑. 有两个应用程序App1和App2,在App1的Activity A中点击button 启动 App2中的Activity B. 通过分析以上ActivityB的启动过程来了解AMS对

Android后台杀死系列之一:FragmentActivity及PhoneWindow后台杀死处理机制

App在后台久置后,再次从桌面或最近的任务列表唤醒时经常会发生崩溃,这往往是App在后台被系统杀死,再次恢复的时候遇到了问题,而在使用FragmentActivity+Fragment的时候会更加频繁.比如,如果Fragment没有提供默认构造方法,就会在重建的时候因为反射创建Fragment失败而崩溃,再比如,在onCreate里面new 一个FragmentDialog,并且show,被后台杀死后,再次唤醒的时候,就会show两个对话框,这是为什么?其实这就涉及了后台杀死及恢复的机制,其中涉

你真的了解Android Notification吗?

最近时不时地有人问我这样或那样的通知如何实现,所以本文将根据个人经验对Notification做个总结,以供参考! 什么是通知(Notification) 通知是一个可以在应用程序正常的用户界面之外显示给用户的消息. 通知发出时,它首先出现在状态栏的通知区域中,用户打开通知抽屉可查看通知详情.通知区域和通知抽屉都是用户可以随时查看的系统控制区域. 作为安卓用户界面的重要组成部分,通知有自己的设计指南.在Android 5.0(API level 21)中引入的 Material Design 的

Android 5.0以上heads up通知

适用Android系统: 1) Android版本>= 5.0 2) 部分ROM是不支持 RemoteViews view=getRemoteViews(body,title, R.mipmap.ic_report_problem_red_24px, 0, date); if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.L){ notification.headsUpContentView=view; notification.vibrate= new

Android应用开发经常使用知识

在其它站点看到的,Mark一下 1.近期打开的应用不在近期任务列表中显示 android:excludeFromRecents="true" 设置为true,则排除在近期任务列表之外,不在近期任务列表中显示 2.推断一个一个String str 是否为NULL或者是否为空字符串 TextUtils.isEmpty(str) 3.android:imeOptions="actionSearch|flagNoFullscreen"的使用方法 在做一个把EditText放

得到手机中最近开启的App

我做悬浮窗的时候需要得到最近开启过的程序,包含图标.包名.应用名等等. 方法是从网上找的,原地址:http://www.apkbus.com/android-127953-1-1.html 其实里面就两个步骤:1.加载最近任务:2.给listview装载适配器 1.加载最近的任务 ,其中appNumber是加载的最近app的总数. /** * 核心方法,加载最近启动的应用程序 注意:这里我们取出的最近任务为 MAX_RECENT_TASKS + * 1个,因为有可能最近任务中包好Launcher

Android4.4 之Bluetooth整理

Android 4.4上蓝牙协议栈采用的是BRCM和Google共同开发的bluedroid,代替了之前的Bluez. 一. Bluetooth 源码分布 (基于Android 4.4 ) 1.  packages/apps/Settings/src/com/android/settings/bluetooth      bluetooth Settings 代码 2.  packages/apps/Bluetooth BT 应用层代码,及BT profile(如:A2dp,gatt,hdp,h