pocheshire / BottomNavigationBar

Bottom Navigation Bar for Xamarin
214 stars 70 forks source link

OnRestoreInstanceState() must not try to deserialize STATE_BADGE_STATES_BUNDLE if no badge state has been saved #8

Closed nextmunich closed 8 years ago

nextmunich commented 8 years ago

When the BottomBar is attached to an Activity which is re-created from saved state, the BottomBar throws an Exception if no badges have been set. This is caused by OnRestoreInstanceState() always deserializing the value of the saved state key STATE_BADGE_STATES_BUNDLE even if the OnSaveInstanceState() method did not save any state for that key.

Steps to reproduce:

  1. Create an Activity which attaches the BottomBar in OnCreate(), passing the saved instance state to the BottomBar
  2. Enable "Kill Activities" in Developer Options on the device
  3. Launch the app
  4. Press the home button to send the app to the background
  5. Open the app from multitasking

The following crash occurs:

System.ArgumentNullException: Value cannot be null. Parameter name: value at Newtonsoft.Json.Utilities.ValidationUtils.ArgumentNotNull (System.Object value, System.String parameterName) [0x00003] in <filename unknown>:0 at Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value) [0x00000] in <filename unknown>:0 at BottomNavigationBar.BottomBar.OnRestoreInstanceState (Android.OS.Bundle savedInstanceState) [0x00024] in <filename unknown>:0 at BottomNavigationBar.BottomBar.Attach (Android.Views.View view, Android.OS.Bundle savedInstanceState) [0x0000c] in <filename unknown>:0 at BSiBankingXamarin.UI.Droid.NMBottomBarActivity1[TViewModel].ConfigureAndAddBottomBar (Android.OS.Bundle savedInstanceState) [0x00011] in /Users/bb/Development/NEXT/BSiBankingXamarin/BSiBankingXamarin.UI.Droid/Classes/Views/_Base/NMBottomBarActivity.cs:45 at BSiBankingXamarin.UI.Droid.NMBottomBarActivity1[TViewModel].OnPostCreate (Android.OS.Bundle savedInstanceState) [0x0000a] in /Users/bb/Development/NEXT/BSiBankingXamarin/BSiBankingXamarin.UI.Droid/Classes/Views/_Base/NMBottomBarActivity.cs:37 at BSiBankingXamarin.UI.Droid.TabRootView.OnPostCreate (Android.OS.Bundle savedInstanceState) [0x00003] in /Users/bb/Development/NEXT/BSiBankingXamarin/BSiBankingXamarin.UI.Droid/Classes/Views/Activities/TabRootView.cs:63 at Android.App.Activity.n_OnPostCreate_Landroid_os_Bundle_ (IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState) [0x00011] in /Users/builder/data/lanes/3340/4e275588/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.App.Activity.cs:3445 at at (wrapper dynamic-method) System.Object:2f4462a7-b3cd-41c6-9f45-a970d74ae1eb (intptr,intptr,intptr)