views-widgets-samples icon indicating copy to clipboard operation
views-widgets-samples copied to clipboard

ViewPager2 incompatible with MapView

Open badvok666 opened this issue 4 years ago • 7 comments

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?

badvok666 avatar Feb 26 '20 09:02 badvok666

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.

mattcrwi avatar Apr 08 '20 19:04 mattcrwi

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.

peterdk avatar Aug 10 '20 19:08 peterdk

I have this bug too. I fixed with generating the bunch of ids, but I wait for an official fix.

gaglileo avatar Nov 25 '20 18:11 gaglileo

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 .

sasasaiki avatar Apr 16 '21 09:04 sasasaiki

I have same issue, any can suggest me a solution?

binhbk230 avatar May 02 '21 11:05 binhbk230

I have same issue, any can suggest me a solution? @binhbk230 It helped for me https://stackoverflow.com/a/59989710

sasasaiki avatar May 02 '21 14:05 sasasaiki

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

binhbk230 avatar May 02 '21 14:05 binhbk230