Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android4.4 近期任務列表RecentsActivity與RecentTasksLoader

Android4.4 近期任務列表RecentsActivity與RecentTasksLoader

編輯:關於Android編程

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 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 tasks = new ArrayList();


// 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();
firstScreenful = false;
//break;
}
++index;
}
}


if (!isCancelled()) {
publishProgress(tasks);
if (firstScreenful) {
// always should publish two updates
publishProgress(new ArrayList());
}
}


while (true) {
try {
tasksWaitingForThumbnails.put(new TaskDescription());
break;
} catch (InterruptedException e) {
}
}


Process.setThreadPriority(origPri);
return null;
}
};
mTaskLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
loadThumbnailsAndIconsInBackground(tasksWaitingForThumbnails);
}

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved