material-components-android icon indicating copy to clipboard operation
material-components-android copied to clipboard

[BottomNavigationView] crash when bundling bottomnavigationview

Open randypfohl opened this issue 7 years ago • 3 comments

Description: Crashlytics is reporting multiple instances following error, which points a bug at the bottom navigation view. I haven't nailed down the issue, looking through the source code it seems you are making the class loaders correctly. I'm unsure of all the states that are being managed here or if there is a state where a parcelable will store a null but will keep digging. In the mean time, hoping someone with insight could help me figure this out. We will be disabling the saving functionality of the bottom nav bar in the mean time.

Fatal Exception: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: com.google.android.material.bottomnavigation.BottomNavigationView$SavedState
       at android.os.Parcel.readParcelableCreator + 2855(Parcel.java:2855)
       at android.os.Parcel.readParcelable + 2781(Parcel.java:2781)
       at android.os.Parcel.readValue + 2684(Parcel.java:2684)
       at android.os.Parcel.readSparseArrayInternal + 3134(Parcel.java:3134)
       at android.os.Parcel.readSparseArray + 2367(Parcel.java:2367)
       at android.os.Parcel.readValue + 2741(Parcel.java:2741)
       at android.os.Parcel.readArrayMapInternal + 3053(Parcel.java:3053)
       at android.os.BaseBundle.initializeFromParcelLocked + 288(BaseBundle.java:288)
       at android.os.BaseBundle.unparcel + 232(BaseBundle.java:232)
       at android.os.Bundle.getSparseParcelableArray + 1010(Bundle.java:1010)
       at com.android.internal.policy.PhoneWindow.restoreHierarchyState + 2204(PhoneWindow.java:2204)
       at android.app.Activity.onRestoreInstanceState + 1204(Activity.java:1204)
       at android.app.Activity.performRestoreInstanceState + 1159(Activity.java:1159)
       at android.app.Instrumentation.callActivityOnRestoreInstanceState + 1317(Instrumentation.java:1317)
       at android.app.ActivityThread.handleStartActivity + 3215(ActivityThread.java:3215)
       at android.app.servertransaction.TransactionExecutor.performLifecycleSequence + 185(TransactionExecutor.java:185)
       at android.app.servertransaction.TransactionExecutor.cycleToPath + 170(TransactionExecutor.java:170)
       at android.app.servertransaction.TransactionExecutor.executeLifecycleState + 147(TransactionExecutor.java:147)
       at android.app.servertransaction.TransactionExecutor.execute + 73(TransactionExecutor.java:73)
       at android.app.ActivityThread$H.handleMessage + 2038(ActivityThread.java:2038)
       at android.os.Handler.dispatchMessage + 106(Handler.java:106)
       at android.os.Looper.loop + 226(Looper.java:226)
       at android.app.ActivityThread.main + 7183(ActivityThread.java:7183)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run + 576(RuntimeInit.java:576)

Expected behavior: If the material design component is saving state for performance reasons, there shouldn't be a reason that the state should cause a crash through normal lifecycle events.

Source code: We aren't doing anything advanced here

In our activity we are using the binding to simply set up with nav controller

        bottomNavigationView = binding.bottomNavigation

        val navController = Navigation.findNavController(this, R.id.teams_nav_fragment)
        bottomNavigationView.setupWithNavController(navController)

In our xml

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <fragment
                android:id="@+id/frag"
                android:name="androidx.navigation.fragment.NavHostFragment"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                app:defaultNavHost="true"
                app:navGraph="@navigation/nav_test" />

            <com.google.android.material.bottomnavigation.BottomNavigationView
                android:id="@+id/bottom_navigation"
                android:layout_width="match_parent"
                android:layout_height="56dp"
                android:layout_gravity="bottom"
                android:background="?attr/bottom_nav_background"
                app:elevation="0dp"
                app:itemIconTint="?attr/bottom_nav_selector"
                app:itemTextColor="?attr/bottom_nav_selector"
                app:menu="@menu/menu_bottom_navigation"
                app:labelVisibilityMode="labeled"/>
        </LinearLayout>

Android API version: Android 9 PIE, api 28 Material Library version: 1.1.0-alpha03

Device: Pixel 3

randypfohl avatar Aug 29 '19 20:08 randypfohl

Is this crash being reported on the latest alpha version?

wcshi avatar Aug 30 '19 15:08 wcshi

So we ended up turning saving off on the view and allowing navigation architecture to manage the state instead. I did try to upgrade to the latest alpha version but the new restrictions regarding menu builder prevented us from upgrading as it would require a sizable refactor.

Ultimately we are avoiding the bug now, and unable to update until we have more time. I doubt we will allow the view to manage it's own bundle on unless it is directly addressed at some point. FatalExceptions in production aren't the best way to test things.

randypfohl avatar Sep 03 '19 17:09 randypfohl

apologies, didn't mean to close. Hoping someone else would run into a similar issue and allow this thread to continue

randypfohl avatar Sep 03 '19 17:09 randypfohl