Lifecycle Info


#1

I think its important to emphasize what happens when the bundle is null. You mention how state is maintained unless device is turned off, etc. But, your example code does not log the case where Bundle is null. The example code should include:

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
Log.i(TAG, “onRestoreInstanceState - iff Bundle not null”);
}

Note: Or update onCreate to log Bundle is null.

On older versions of android it was possible to use Task Killer applications (and others), resulting in null Bundle for application being force-stopped. The result usedtobe the bundle state would be lost, rather than maintained as mentioned above. But, in current updates of android versions (I tested 2.3.4 and 4.x) I am no longer able to reproduce the lost cases.

With the above code you do not see onRestoreInstanceState called if Bundle is null, similar to what could be learned if logging null Bundle in your example’s onCreate.


#2

Thanks, BobSmith, for another fine example of why it’s really hard to write a comprehensive beginning Android programming book. The frameworks are filled with lovely historical quirks like this one, and I fear if we had included them all we’d have a thousand-page doorstop rather than a 600-page magnum opus.


#3

True. I suppose it is enough to realize the Bundle can be null. This side effect may require you to ensure your app survives via onPause/onResume or other.

It seems wonderful when I think how many fixes are in current SDK releases, until the reality of delayed mobile vendor update schedules hits home again. LOL

I do not think the book needs to be expanded. Maybe a topical reference list of known issues & discussions on various forums is useful for further reading.