当activity在oncreate()中进行了初始化,随之开始进入onresume()方法。这就意味着,该activity处于前台,并且拥有用户的焦点。
那么我们看一下,onResume()中进行了什么操作:
protected void onResume()
getApplication().dispatchActivityResumed(this);
mActivityTransitionState.onResume();
mCalled = true;
}
第一行是告诉应用程序,这个activity已经处于onresume状态
第二行 是设置activity的状态为onresume
第三行 表明已经调用基类的方法
onresume()
@Override
protected void onResume() {
long startTime = 0;
if (DEBUG_RESUME_TIME) {
startTime = System.currentTimeMillis();
Log.v(TAG, "Launcher.onResume()");
}
if (mLauncherCallbacks != null) {
mLauncherCallbacks.preOnResume();
}
super.onResume();
/*
* onresumestat表示launcher的显示状态
* 根据这个参数,进行桌面,应用程序菜单,或者小部件的吓死你还
*
* */
// Restore the previous launcher state
if (mOnResumeState == State.WORKSPACE) {
showWorkspace(false);
} else if (mOnResumeState == State.APPS) {
boolean launchedFromApp = (mWaitingForResume != null);
// Don't update the predicted apps if the user is returning to launcher in the apps
// view after launching an app, as they may be depending on the UI to be static to
// switch to another app, otherwise, if it was
showAppsView(false /* animated */, false /* resetListToTop */,
!launchedFromApp /* updatePredictedApps */, false /* focusSearchBar */);
} else if (mOnResumeState == State.WIDGETS) {
showWidgetsView(false, false);
}
// 最后设置这个参数为none
mOnResumeState = State.NONE;
//根据不同的状态显示背景,背景在onpause中设置为渐变
// Background was set to gradient in onPause(), restore to transparent if in all apps.
setWorkspaceBackground(mState == State.WORKSPACE ? WORKSPACE_BACKGROUND_GRADIENT
: WORKSPACE_BACKGROUND_TRANSPARENT);
mPaused = false;
/*
* 这两个参数分别是 是否需要恢复 以及是否在launcher显示的时候加载界面
* */
if (mRestoring || mOnResumeNeedsLoad) {
// 设置桌面为加载状态
setWorkspaceLoading(true);
// If we're starting binding all over again, clear any bind calls we'd postponed in
// the past (see waitUntilResume) -- we don't need them since we're starting binding
// from scratch again
// 如果我们将要绑定所有,那么清理掉以前所有的绑定
mBindOnResumeCallbacks.clear();
//invalid 加载数据
mModel.startLoader(PagedView.INVALID_RESTORE_PAGE);
// 两个参数这只为false
mRestoring = false;
mOnResumeNeedsLoad = false;
}
/*
* launcher的界面加载时一个异步的过程,例如快捷方式,组件的加载,它们被放在launcher的内存中
* 这时候会一个个的取出来,然后进行调用,一个个的进行显示
* */
if (mBindOnResumeCallbacks.size() > 0) {
// We might have postponed some bind calls until onResume (see waitUntilResume) --
// execute them here
long startTimeCallbacks = 0;
if (DEBUG_RESUME_TIME) {
startTimeCallbacks = System.currentTimeMillis();
}
for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
mBindOnResumeCallbacks.get(i).run();
}
mBindOnResumeCallbacks.clear();
if (DEBUG_RESUME_TIME) {
Log.d(TAG, "Time spent processing callbacks in onResume: " +
(System.currentTimeMillis() - startTimeCallbacks));
}
}
/*
* 这里保存的是快捷方式以及组件的删除任务
*
* */
if (mOnResumeCallbacks.size() > 0) {
for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
mOnResumeCallbacks.get(i).run();
}
mOnResumeCallbacks.clear();
}
// Reset the pressed state of icons that were locked in the press state while activities
// were launching
// 在app启动的时候,其快捷方式处于选中该状态,清除这个状态
if (mWaitingForResume != null) {
// Resets the previous workspace icon press state
mWaitingForResume.setStayPressed(false);
}
// It is possible that widgets can receive updates while launcher is not in the foreground.
// Consequently, the widgets will be inflated in the orientation of the foreground activity
// (framework issue). On resuming, we ensure that any widgets are inflated for the current
// orientation.
// 确保所有组件被初始化
getWorkspace().reinflateWidgetsIfNecessary();
reinflateQSBIfNecessary();
if (DEBUG_RESUME_TIME) {
Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
}
if (mWorkspace.getCustomContentCallbacks() != null) {
// If we are resuming and the custom content is the current page, we call onShow().
// It is also poassible that onShow will instead be called slightly after first layout
// if PagedView#setRestorePage was set to the custom content page in onCreate().
// 如果第三方定制的页面在当前页,调用onshow方法
if (mWorkspace.isOnOrMovingToCustomContent()) {
mWorkspace.getCustomContentCallbacks().onShow(true);
}
}
updateInteraction(Workspace.State.NORMAL, mWorkspace.getState());
mWorkspace.onResume();
if (!isWorkspaceLoading()) {
// Process any items that were added while Launcher was away.
InstallShortcutReceiver.disableAndFlushInstallQueue(this);
}
if (mLauncherCallbacks != null) {
mLauncherCallbacks.onResume();
}
}