android / architecture-components-samples

Samples for Android Architecture Components.
https://d.android.com/arch
Apache License 2.0
23.46k stars 8.28k forks source link

NavigationAdvancedSample doesnt save/restore RecyclerView state #1063

Open J-Swift opened 2 years ago

J-Swift commented 2 years ago

When navigating between the Leaderboard and other tabs, the Leaderboard is recreated every single time you return. The recycler state should be retained. This is the same issue I'm having with my local app and was hoping that I was doing something wrong but it looks like this is just how Navigation works with a bottom nav?

Repro:

Even if I add onSaveInstanceState it never gets called.

J-Swift commented 2 years ago

Actually, messing around more with this example, I realized it seems the state of the backstack doesnt work at all between tabs. Another example:

I had this same issue locally when trying to setup sub navgraphs, and ended up having to abandon them as a design and use custom back button handling to keep "proper" state maintained.

Is this really working as intended? These all seem like bugs to me, and the most frustrating thing is that this is absolutely the "happy path" of app design. None of the 2 situations I describe seem abnormal, on the contrary it is how apps have been designed for at least a decade.

bqfa commented 1 year ago

In NavigationAdvancedSample I Followed your given step and when select home tab again its still on About page .

But My issue is in my app fragment is recreated