Android - RecyclerView items aren't visible after orientation change

Noa Drach :

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

  • Controller A - shows a summary of images taken
  • Controller B - is the camera interaction

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 :(

  • Does anyone have any idea what is going on?
  • Can you suggest additional directions for investigation?

UPDATE:

  • The recycler view was defined with android:layout_height="wrap_content"
  • Changing to android:layout_height="match_parent" while working with LinearLayoutManager works (looks ugly)
  • Changing it back to FlexboxLayoutManager fails all the flows that worked before

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

Noa Drach :

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=301591&siteId=1