当前位置: 查字典图书网> 互联网> Android开发精要> 大框架不错,细节毛病多

大框架不错,细节毛病多

对“大框架不错,细节毛病多”的回应

飘飘白云 2015-03-13 09:26:08

楼主看得很仔细。作者在这里确实是不准确的,他只看到一处地方的源码而没有看全部源码。

我贴上4.2.2版本的源码放这里就清楚了:

总共三处地方调用了onSaveInstanceState:
/Android4_2_2/android/frameworks/base/core/java/android/app/ActivityThread.java:
2999 state = new Bundle();
3000 state.setAllowFds(false);
3001: mInstrumentation.callActivityOnSaveInstanceState(r.activity, state);
3002 r.state = state;
3003 }
....
3131 state = new Bundle();
3132 state.setAllowFds(false);
3133: mInstrumentation.callActivityOnSaveInstanceState(r.activity, state);
3134 r.state = state;
3135 } else {
....
3668 r.state = new Bundle();
3669 r.state.setAllowFds(false);
3670: mInstrumentation.callActivityOnSaveInstanceState(r.activity, r.state);
3671 }

在 pause 处理中:
final Bundle performPauseActivity(ActivityClientRecord r, boolean finished,
boolean saveState) {
// Next have the activity save its current state and managed dialogs...
if (!r.activity.mFinished && saveState) {
state = new Bundle();
state.setAllowFds(false);
mInstrumentation.callActivityOnSaveInstanceState(r.activity, state);
r.state = state;
}
// Now we are idle.
r.activity.mCalled = false;
mInstrumentation.callActivityOnPause(r.activity);
EventLog.writeEvent(LOG_ON_PAUSE_CALLED, UserHandle.myUserId(),
r.activity.getComponentName().getClassName());
if (!r.activity.mCalled) {
throw new SuperNotCalledException(
"Activity " + r.intent.getComponent().toShortString() +
" did not call through to super.onPause()");
}
}

在 stop 处理中:
private void performStopActivityInner(ActivityClientRecord r,
StopInfo info, boolean keepShown, boolean saveState) {
// Next have the activity save its current state and managed dialogs...
if (!r.activity.mFinished && saveState) {
if (r.state == null) {
state = new Bundle();
state.setAllowFds(false);
mInstrumentation.callActivityOnSaveInstanceState(r.activity, state);
r.state = state;
} else {
state = r.state;
}
}

if (!keepShown) {
try {
// Now we are idle.
r.activity.performStop();
} catch (Exception e) {
if (!mInstrumentation.onException(r.activity, e)) {
throw new RuntimeException(
"Unable to stop activity "
+ r.intent.getComponent().toShortString()
+ ": " + e.toString(), e);
}
}
r.stopped = true;
}

r.paused = true;
}

还有一处是在 relaunch 处理中:
private void handleRelaunchActivity(ActivityClientRecord tmp) {
// Need to ensure state is saved.
if (!r.paused) {
performPauseActivity(r.token, false, r.isPreHoneycomb());
}
if (r.state == null && !r.stopped && !r.isPreHoneycomb()) {
r.state = new Bundle();
r.state.setAllowFds(false);
mInstrumentation.callActivityOnSaveInstanceState(r.activity, r.state);
}

handleDestroyActivity(r.token, false, configChanges, true);

r.startsNotResumed = tmp.startsNotResumed;

handleLaunchActivity(r, currentIntent);
}

《Android开发精要》热门书评


书名: Android开发精要
作者: 范怀宇
出版社: 机械工业出版社
出版年: 2012-8
页数: 356
定价: 69.00元
ISBN: 9787111390589