android activity 生命周期细节

android activity 生命周期细节

该图中,

protected void onStart() {
mCalled = true;
}

protected void onRestart() {
mCalled = true;
}

protected void onResume() {

mCalled = true;
}

protected void onPause() {
mCalled = true;
}

protected void onStop() {
mCalled = true;
}

protected void onDestroy() {
mCalled = true;


// dismiss any dialogs we are managing.
if (mManagedDialogs != null) {
final int numDialogs = mManagedDialogs.size();
for (int i = 0; i < numDialogs; i++) {
final ManagedDialog md = mManagedDialogs.valueAt(i);
if (md.mDialog.isShowing()) {
md.mDialog.dismiss();
}
}
mManagedDialogs = null;
}


// close any cursors we are managing.
synchronized (mManagedCursors) {
int numCursors = mManagedCursors.size();
for (int i = 0; i < numCursors; i++) {
ManagedCursor c = mManagedCursors.get(i);
if (c != null) {
c.mCursor.close();
}
}
mManagedCursors.clear();
}


// Close any open search dialog
if (mSearchManager != null) {
mSearchManager.stopSearch();
}
}

而在设置mCalled为false的函数里面,设置为false后立马就设置为true,这些函数下面一般就是异常处理,就是说只 包含mCalled=true的函数就没有什么实际意义了。

这样看,发现这几个onResume(),start(0,restart(),onPause()只是起到方便理解的作用而已。周期图可以再简化。

(当然,如果后面有单独调用到这些函数,就另当别论,没去check)