LoaderTask.java
可以看到LoaderTask实现了Runnable接口,直接去看该类的run() 方法public void run() { boolean isUpgrade = false; synchronized (mLock) {
mIsLoaderTaskRunning = true;
} // Optimize for end-user experience: if the Launcher is up and // running with the
// All Apps interface in the foreground, load All Apps first. Otherwise, load the
// workspace first (default).
keep_running: { // Elevate priority when Home launches for the first time to avoid
// starving at boot time. Staring at a blank home is not cool.
synchronized (mLock) { if (DEBUG_LOADERS) Log.d(TAG, "Setting thread priority to " +
(mIsLaunching ? "DEFAULT" : "BACKGROUND"));
android.os.Process.setThreadPriority(mIsLaunching
? Process.THREAD_PRIORITY_DEFAULT : Process.THREAD_PRIORITY_BACKGROUND);
} if (DEBUG_LOADERS) Log.d(TAG, "step 1: loading workspace"); //加载一级菜单的方法
isUpgrade = loadAndBindWorkspace(); if (mStopped) { break keep_running;
} // Whew! Hard work done. Slow us down, and wait until the UI thread has
// settled down.
synchronized (mLock) { if (mIsLaunching) { if (DEBUG_LOADERS) Log.d(TAG, "Setting thread priority to BACKGROUND");
android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
}
}
waitForIdle(); // second step
if (DEBUG_LOADERS) Log.d(TAG, "step 2: loading all apps"); //加载二级菜单里面的方法
loadAndBindAllApps(); // Restore the default thread priority after we are done loading items
synchronized (mLock) {
android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
}
} // Update the saved icons if necessary
if (DEBUG_LOADERS) Log.d(TAG, "Comparing loaded icons to database icons"); synchronized (sBgLock) { for (Object key : sBgDbIconCache.keySet()) {
updateSavedIcon(mContext, (ShortcutInfo) key, sBgDbIconCache.get(key));
}
sBgDbIconCache.clear();
} if (AppsCustomizePagedView.DISABLE_ALL_APPS) { // Ensure that all the applications that are in the system are
// represented on the home screen.
if (!UPGRADE_USE_MORE_APPS_FOLDER || !isUpgrade) {
verifyApplications();
}
} // Clear out this reference, otherwise we end up holding it until all of the
// callback runnables are done.
mContext = null; synchronized (mLock) { // If we are still the last one to be scheduled, remove ourselves.
if (mLoaderTask == this) {
mLoaderTask = null;
}
mIsLoaderTaskRunning = false;
}
}
可以看到在该类中主要有两个方法,
下面着重分析下这两个方法的加载流程loadAndBindWorkSpace(), WorkSpace是一级菜单里面的容器类,该方法是加载一及菜单的方法
loadAndBindAllapp() ,这是抽屉内二级菜单的加载方法