I have a MainActivity which holds TabHost one of its tabs is CardHolderActivity which also contains a TabHost with two tabs (and they are Activities also). Everything goes fine until after I set in one of the latest - MyCardsActivity - the SaveOnInstanceState where I put a list of my data to outState bundle. I'm starting a lot of other apps so my app is being killed. After I start it again from the list of recently opened application I'm getting a NullPointerException, here is the log:
05-30 12:35:06.032: I/CrashLogger(28147): java.lang.RuntimeException: Unable to start activity ComponentInfo{my.package/my.package.activities.MainActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{my.package/my.package.activities.CardsHolderActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{my.package/my.package.activities.MyCardsActivity}: java.lang.NullPointerException
05-30 12:35:06.032: I/CrashLogger(28147): --------- Stack trace ---------
05-30 12:35:06.032: I/CrashLogger(28147): android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-30 12:35:06.032: I/CrashLogger(28147): android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-30 12:35:06.032: I/CrashLogger(28147): android.app.ActivityThread.access$600(ActivityThread.java:141)
05-30 12:35:06.032: I/CrashLogger(28147): android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-30 12:35:06.032: I/CrashLogger(28147): android.os.Handler.dispatchMessage(Handler.java:99)
05-30 12:35:06.032: I/CrashLogger(28147): android.os.Looper.loop(Looper.java:137)
05-30 12:35:06.032: I/CrashLogger(28147): android.app.ActivityThread.main(ActivityThread.java:5041)
05-30 12:35:06.032: I/CrashLogger(28147): java.lang.reflect.Method.invokeNative(Native Method)
05-30 12:35:06.032: I/CrashLogger(28147): java.lang.reflect.Method.invoke(Method.java:511)
05-30 12:35:06.032: I/CrashLogger(28147): com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-30 12:35:06.032: I/CrashLogger(28147): com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-30 12:35:06.032: I/CrashLogger(28147): dalvik.system.NativeStart.main(Native Method)
Here is the code after which I have this:
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (cards != null)
outState.putSerializable(EXTRA_MY_CARDS, cards);
}
The cards is a static variable of TreeSet<Card> type and Card class implements Serializable.
Can you guys tell me why this happens?
Also, I'm very surprised this happens after restoring the application for killed state, there is no any issues on the onSaveInstanceState() at all. And I'm not retrieving the date nor in onRestoreInstanceState() and onCreate() neither.