Fixed
Status Update
Comments
jb...@google.com <jb...@google.com>
te...@gmail.com <te...@gmail.com> #2
Hi Ed, Thank you so much for these suggestions. I've been reviewing them and merging them in. Hopefully it should be live. I've included a thank you note too in the article.
cl...@google.com <cl...@google.com>
cl...@google.com <cl...@google.com> #3
Great! Thanks a lot, I'll look for the live updates soon!
ap...@google.com <ap...@google.com> #4
Project: platform/frameworks/support
Branch: androidx-main
commit 6899e1031ecb6d9421c0e986a9290388c84e8a27
Author: Clara Fok <clarafok@google.com>
Date: Mon Oct 23 18:33:17 2023
Fix nested ViewModel not cleared
Ensure that child Fragment's ViewModel is cleared when the Parent ViewModel is destroyed during clearBackStack.
Test: ./gradlew fragment:fragment:cC
Bug: 296173018
Relnote: "Nested Fragment's ViewModel will now be cleared when parent ViewModel is cleared"
Change-Id: I6d83cd93421837b213d25d2fdbe5405348cd2637
M fragment/fragment/src/androidTest/java/androidx/fragment/app/FragmentManagerViewModelTest.kt
M fragment/fragment/src/androidTest/java/androidx/fragment/app/SaveRestoreBackStackTest.kt
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManagerViewModel.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentStateManager.java
https://android-review.googlesource.com/2796453
Branch: androidx-main
commit 6899e1031ecb6d9421c0e986a9290388c84e8a27
Author: Clara Fok <clarafok@google.com>
Date: Mon Oct 23 18:33:17 2023
Fix nested ViewModel not cleared
Ensure that child Fragment's ViewModel is cleared when the Parent ViewModel is destroyed during clearBackStack.
Test: ./gradlew fragment:fragment:cC
Bug: 296173018
Relnote: "Nested Fragment's ViewModel will now be cleared when parent ViewModel is cleared"
Change-Id: I6d83cd93421837b213d25d2fdbe5405348cd2637
M fragment/fragment/src/androidTest/java/androidx/fragment/app/FragmentManagerViewModelTest.kt
M fragment/fragment/src/androidTest/java/androidx/fragment/app/SaveRestoreBackStackTest.kt
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManagerViewModel.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentStateManager.java
te...@gmail.com <te...@gmail.com> #5
Great!
na...@google.com <na...@google.com> #6
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.fragment:fragment:1.6.2
pr...@google.com <pr...@google.com> #7
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.fragment:fragment:1.7.0-alpha07
Description
Version used: 2.6.0
Devices/Android versions reproduced on: every device & tested in above SDK 23
If this is a bug in the library, we would appreciate if you could attach:
- Sample project to trigger the issue.
- A screenrecord or screenshots showing the issue (if UI related).
Issue:
When using navigation component in fragment, the destination fragment's viewModel (which configured savedState & restoreState) is not cleared even though the destination popped from backstack.
For clearing destination's VM, I should call `navController.clearBackStack(destinationId)`.
I know It is intended feature for preserving VM's state for later restore.
However, the problem happens in the situation that the destination fragment has nested fragment and nested fragment has its VM (call nested VM).
Nested VM never cleared when call `navController.clearBackStack(destinationId)` of parent fragment.
Sadly, VM never cleared even though activity is destroyed. (if application not terminated)
I attached sample project and screen record for reproduce.