Launcher系列目录:
一、android7.x Launcher3源码解析(1)—启动流程
二、android7.x Launcher3源码解析(2)—框架结构
三、android7.x Launcher3源码解析(3)—workspace和allapps加载流程
前两篇博客分别对Lancher的启动和Launcher的框架结构进行了一些分析,这一篇,将着重开始分析界面的加载流程。
1、整体流程
先上一张整体的流程图吧。(图片看不清可以下载下来看或者右击新开个页面查看图片)
先从Launcher.java的onCreate方法开始,
protected void onCreate(Bundle savedInstanceState) {
......
//建立LauncherAppState对象
LauncherAppState.setApplicationContext(getApplicationContext());
LauncherAppState app = LauncherAppState.getInstance();
......
//建立LauncherModel对象
mModel = app.setLauncher(this);
//一些其他对象初始化
......
setContentView(R.layout.launcher);
setupViews();
if (!mRestoring) {
if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
// If the user leaves launcher, then we should just load items asynchronously when
// they return.
mModel.startLoader(PagedView.INVALID_RESTORE_PAGE);
} else {
// We only load the page synchronously if the user rotates (or triggers a
// configuration change) while launcher is in the foreground
mModel.startLoader(mWorkspace.getRestorePage());
}
}
......
}
重点调用了LauncherModel的startLoader的方法,startLoader里面,最重要的就是启动了LoaderTask,mLoaderTask = new LoaderTask(mApp.getContext(), synchronousBindPage);
我们接着分析LoaderTask的run方法。
public void run() {
......
keep_running: {
if (DEBUG_LOADERS) Log.d(TAG, "step 1: loading workspace");
loadAndBindWorkspace();
if (mStopped) {
break keep_running;
}
waitForIdle();
// second step
if (DEBUG_LOADERS) Log.d(TAG, "step 2: loading all apps");
loadAndBindAllApps();