title: Bundle null in onRestoreInstanceState?
body: <p>I recently received a crash in my program. Using logCat I determined that the crash was due to code in my <code>onRestoreInstanceState()</code> in the main activity when my app is being resumed. Logcat file:</p>
  
  <pre><code>07-23 16:27:01.927 I/ActivityManager(  390): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.myapp/.MainActivity bnds=[1184,809][1376,1001]} from pid 30666
  
  07-23 16:27:01.997 I/ActivityManager(  390): Start proc com.myapp for activity com.myapp/.MainActivity: pid=31007 uid=10070 gids={50070, 1028}
  
  07-23 16:27:02.137 E/AndroidRuntime(31007): FATAL EXCEPTION: main
  
  
  07-23 16:27:02.137 E/AndroidRuntime(31007): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp/com.myapp.MainActivity}: java.lang.ClassCastException: android.os.Parcelable[] cannot be cast to com.myapp.Panel[]
  
  07-23 16:27:02.137 E/AndroidRuntime(31007):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
  
  07-23 16:27:02.137 E/AndroidRuntime(31007):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
  
  07-23 16:27:02.137 E/AndroidRuntime(31007):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
  
  07-23 16:27:02.137 E/AndroidRuntime(31007):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
  
  07-23 16:27:02.137 E/AndroidRuntime(31007):     at android.os.Handler.dispatchMessage(Handler.java:99)
  
  07-23 16:27:02.137 E/AndroidRuntime(31007):     at android.os.Looper.loop(Looper.java:137)
  
  07-23 16:27:02.137 E/AndroidRuntime(31007):     at android.app.ActivityThread.main(ActivityThread.java:5041)
  
  07-23 16:27:02.137 E/AndroidRuntime(31007):     at java.lang.reflect.Method.invokeNative(Native Method)
  
  07-23 16:27:02.137 E/AndroidRuntime(31007):     at java.lang.reflect.Method.invoke(Method.java:511)
  
  07-23 16:27:02.137 E/AndroidRuntime(31007):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  
  07-23 16:27:02.137 E/AndroidRuntime(31007):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  
  07-23 16:27:02.137 E/AndroidRuntime(31007):     at dalvik.system.NativeStart.main(Native Method)
  
  07-23 16:27:02.137 E/AndroidRuntime(31007): Caused by: java.lang.ClassCastException: android.os.Parcelable[] cannot be cast to com.myapp.Panel[]
  
  07-23 16:27:02.137 E/AndroidRuntime(31007):     at com.myapp.MainActivity.onRestoreInstanceState(MainActivity.java:177)
  
  07-23 16:27:02.137 E/AndroidRuntime(31007):     at android.app.Activity.performRestoreInstanceState(Activity.java:910)
  
  07-23 16:27:02.137 E/AndroidRuntime(31007):     at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1131)
  
  07-23 16:27:02.137 E/AndroidRuntime(31007):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2158)
  
  07-23 16:27:02.137 E/AndroidRuntime(31007):     ... 11 more
  
  07-23 16:27:02.167 W/ActivityManager(  390):   Force finishing activity com.myapp/.MainActivity
  </code></pre>
  
  <p>The crash occurs on the line <code>mPanels = (Panel[]) inState.getParcelableArray("panelParcel");</code> in the onRestoreInstanceState method below. </p>
  
  <p>This methodology has worked robustly for me until this crash, and I'm trying to figure out why the inState appears to not have the array of objects (Panels) that I've saved in it. I'm confused because it seems like the inState doesnt include the panelParcel that I've saved to it. </p>
  
  <p>I see from <a href="https://stackoverflow.com/questions/4096169/onsaveinstancestate-and-onrestoreinstancestate">this question</a> I should typically be using <code>onCreate</code> instead of <code>onRestoreInstanceState</code>, but I'd love to understand why this wouldnt work in a rare case, perhaps I dont fully understand something about the Activity Lifecycle? </p>
  
  <p>Code for both Save and Restore Instance State: </p>
  
  <pre><code>@Override
  public void onSaveInstanceState(@NotNull Bundle outState)
  {
      Log.d("panelCreation", "onSaveInstanceState Called");
      super.onSaveInstanceState(outState);
      // save the current panel state
      outState.putParcelableArray("panelParcel", mPanels);
  }
  
  @Override
  public void onRestoreInstanceState(Bundle inState)
  {
      Log.d("panelCreation", "onsState Called");
      super.onRestoreInstanceState(inState);
  
      // Note getParcelable returns a *new* array, so we must setup the drawer listener after this
      mPanels = (Panel[]) inState.getParcelableArray("panelParcel");
      // set up the drawer's list view with items and click listener
      mDrawerList.setAdapter(new PanelArrayAdapter(this,
              R.layout.drawer_list_item, mPanels));
      refreshDrawerListChecked();
  
      // Forces the Adapter to redraw the view to ensure color stylings are applied
      ((PanelArrayAdapter)mDrawerList.getAdapter()).notifyDataSetChanged();
  }
  </code></pre>