views-widgets-samples
views-widgets-samples copied to clipboard
ViewPager2 incompatible with MapView
Having these two Ui elements in the same view, calling onCreate(bundle) for the mapView, then navigating away and returning will cause:
java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class androidx.recyclerview.widget.RecyclerView$SavedState instead.
It is caused by both mapView and ViewPager using ViewCompat.generateViewId() and i guess somehow ending up with the same viewId. (Although i have no idea how)
Specifically for viewPager2 mRecyclerView.setId(ViewCompat.generateViewId()); is probably causing it.
This stack overflow's current solution is call ViewCompat.generateViewId() a bunch to take the view id's. Again that doesn't make sense to me since if they do both user ViewCompat.generateViewId() they should get different views. Maybe mapView does it manually and its their issue?
I have the same issue. Thank you so much for finding this. The multi threaded nature of the error made tracking this down so hard.
Wow, we have the same issue, and the 'fix' mentioned indeed does solve our issue. I spend 2 hours debugging this....
I assume that Maps somehow takes a ID of 0x1 statically. And that that's also the first ID generated by the ViewCompat.generateViewId() method. But I am speculating ofcourse. Really weird though to see a bug so specifically tied to our app design.
I have this bug too. I fixed with generating the bunch of ids, but I wait for an official fix.
I have this bug too !!!! I spend 3 hours debugging this !!!! I was saved by this issue. Thank you. I hope it will be fixed officially .
I have same issue, any can suggest me a solution?
I have same issue, any can suggest me a solution? @binhbk230 It helped for me https://stackoverflow.com/a/59989710
I have same issue, any can suggest me a solution? @binhbk230 It helped for me https://stackoverflow.com/a/59989710
Thank you so much, it work perfectly