Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MapView unusable in a RecyclerView #588

Closed
Nodjo opened this issue Apr 26, 2017 · 3 comments
Closed

MapView unusable in a RecyclerView #588

Nodjo opened this issue Apr 26, 2017 · 3 comments
Labels
Milestone

Comments

@Nodjo
Copy link

Nodjo commented Apr 26, 2017

Contrary to a View within an Activity, which is only attached and detached once, Views within RecyclerView items may be attached/detached repeatedly, see RecyclerView.Adapter.onViewAttachedToWindow and RecyclerView.Adapter.onViewDetachedFromWindow.

The MapView does not handle the View lifecycle properly, basically what is undone in onDetachedFromWindow is not done in onAttachedToWindow so it can effectively be attached only once.

A workaround for this issue is to call setHasTransientState(true) on the recycler's item view that contains the mapView. Doing this will prevent the RecyclerView from attempting to reuse the view

@spyhunter99
Copy link
Collaborator

This is a known issue and gets posted here frequently. Glad you found a solution! If we were to make changes to the map view, what should we change?

@Nodjo
Copy link
Author

Nodjo commented Apr 28, 2017

MapView.java implements onDetachedFromWindow but not onAttachedFromWindow. What's currently destroyed in onDetachedFromWindow should be initialized in onAttachedToWindow so that the view can go through a lifecycle where it's detached then attached again. Like onStart/onStop or onResume/onPause for an Activity.

@spyhunter99 spyhunter99 added this to the v5.6.5 milestone Jun 17, 2017
@spyhunter99 spyhunter99 modified the milestones: v5.6.6, v5.6.5 Jul 1, 2017
@spyhunter99
Copy link
Collaborator

well the issue is that stuff is currently destroyed in onDetached that cannot be recreated. It's more like we need a pause/resume mechanism, however that's not part of the View or ViewGroup lifecycle.

setHasTransientState requires API 16 or newer. I'm adding this to the samples now to provide clarification and to the javadocs. This seems to be the only simple solution currently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants