java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.support.v7.widget.Toolbar$SavedState

Problem Fixed in my case:

Issue in my case is :

1:I have an id in xml which have same name as a layout.

ie:in my case ,i have a custom action bar layout named as "action_bar.xml" and an id in another layout as "+id/action_bar".So this cause problem when app is not in the memory and while recreating that page .

NOTE:DONT USE SAME ID/LAYOUT NAMES in more than one time in the app.


This can also happen in this edge case:

If you create a custom view programmatically inside the constructor of another parent view that has the AttributeSet parameter:

   public ToggleButtonDescriptive(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.toggleButton = new SquareToggleButton(ctx, attributeSet);
    }

DO NOT pass the AttributeSet to that child View:

toggleButton = new SquareToggleButton(ctx, attributeSet);

As passing the AttributeSet causes the child view to have the same id as the parent and thus Android tries to restore the parents SavedState to that child view or vice versa. Instead omit the AttributeSet parameter altogether, like this:

toggleButton = new SquareToggleButton(ctx);