Android Activity Lifecycle
I spent the evening studying the Android Activity Lifecycle. Here is the diagram I came up with using Omnigraffle:

This is roughly the same as Figure 2.3 in Hello, Android, although I corrected a bug and added the dashed lines for <<kill>>. Those indicate the OS may kill the Activity when resources are low, so onStop() and/or onDestroy() might not be called. I’m going to use this as a handout when I talk at next month’s OCI Java Lunch.
Confusing Docs
The documentation for Activity contains a confusing statement in the documentation for onRestart():
Called after onStart() when the current activity is being re-displayed to the user (the user has navigated back to it).
I think they mean it is called after the “original” onStart() when the activity was first created, because another part of that same page says this about the onRestart() method:
Called after your activity has been stopped, prior to it being started again. Always followed by onStart()
Studying the Code
Fortunately source code is available for Activity.java:
final void performRestart() {
final int N = mManagedCursors.size();
for (int i=0; i<N; i++) {
ManagedCursor mc = mManagedCursors.get(i);
if (mc.mReleased || mc.mUpdated) {
mc.mCursor.requery();
mc.mReleased = false;
mc.mUpdated = false;
}
}
if (mStopped) {
mStopped = false;
mCalled = false;
mInstrumentation.callActivityOnRestart(this);
if (!mCalled) {
throw new SuperNotCalledException(
"Activity " + mComponent.toShortString() +
" did not call through to super.onRestart()");
}
performStart();
}
}
Based on that, I think it is clear that onRestart() is always followed by onStart().
I’m Not The Only One
Figure 2.3 on page 30 of the new Hello, Android book seems to be based on the misleading comment, because that figure shows onStart() and onRestart() reversed. I submitted the errata here, so I suspect it will be fixed before the paper book is printed.
Now you know how I spend my Saturday nights!
Hey Its nice..
i am working on a nice client and have started digging the android src code and recently was checking out the life cycle model..
This doc has helped me out
Pragnya