After going through the introductory book on Android programming, I wanted to change the sample application to strengthen my understanding of some topics that were not really covered. When making the changes, I made a mistake, but I'm curious why the error worked in some cases, but not in others.
Activity in the application stores a number of questions in the Hashtable<Integer, Question> , where Question is a small class containing an int and two lines. As originally written, activity loads questions from the server on each onCreate() , so I wanted to implement onSaveInstanceState() to prevent some redundant downloads. onSaveInstanceState() saves the Hashtable in the Bundle using putSerializable() .
@Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState);
It worked great to change the screen orientation even before I knew what Parcelable was and how to implement it. I only knew that there was a problem when I pressed the home key of the emulator and the application silently, invisibly crashed without LogCat output. The stack trace led me to search for Parcelable and made Question implement it.
My question is not what I did wrong. The question is: When the Question class did not implement Parcelable, why did the application crash only when you click Home, and not when changing the screen orientation?
android android-activity bundle parcelable activity-lifecycle
erichamion
source share