androidandroid-recyclerviewandroid-orientationandroid-flexboxlayoutconductor

Android - RecyclerView items aren't visible after orientation change


I'm using in my app the Conductor framework.

The app in general is fixed in portrait state, but I have 2 Controllers that use ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR and respond to device orientation changes

so when A is launched, it immediately launches B and shows the summary after images are taken.

A holds a RecyclerView that uses FlexboxLayoutManager (when I tried replacing the layout manager w/ a simple LinearLayoutManager nothing changed)

I have 3 flows that work fine:

  1. The device in held in Portrait -> A is launched -> B is launched -> images are taken -> B is closed -> the images are Shown in A
  2. The device in held in Landscape -> A is launched -> B is launched -> images are taken -> B is closed -> the images are Shown in A
  3. The device in held in Portrait -> A is launched -> B is launched -> device orientation changes to Landscape -> images are taken -> orientation changes to Portrait-> B is closed -> the images are Shown in A

However this scenario fails:

The device in held in Portrait -> A is launched -> B is launched -> device orientation changes to Landscape -> images are taken -> B is closed -> the images are NOT shown in A

In all the flows I see that the adapter is aware of the new items, and getItemViewType, onCreateViewHolder and onBindViewHolder are called with the correct positions

The flow that fails is actually that one that seems most natural to me as a user :(

UPDATE:

So I'm taking a look now at FlexboxLayoutManager to see if I can fix this easily - I don't think that a recycler view is actually needed in my flow


Solution

  • It seems that the solution was just changing the RecyclerView from android:layout_height="wrap_content" to android:layout_height="match_parent".

    In the update above I said that it still doesn't work with FlexboxLayoutManager, but the problem was on my end (too commenting out and in of code).

    The original code wasn't written by me, so I'm not sure why wrap_content was used