Fixed
Status Update
Comments
ap...@google.com <ap...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-main
commit 57ca221882695bd6a52549f4d9ea3b812e6fe87c
Author: Simon Schiller <simonschiller@users.noreply.github.com>
Date: Mon Mar 22 16:09:30 2021
[GH] [FragmentStrictMode] Detect <fragment> tag usage
## Proposed Changes
- Detect `<fragment>` tag usage inside XML layouts
## Testing
Test: See `FragmentStrictModeTest#detectFragmentTagUsage`
## Issues Fixed
Fixes: 153738235
This is an imported pull request fromhttps://github.com/androidx/androidx/pull/141 .
Resolves #141
Github-Pr-Head-Sha: 4ea052596e4341b9f11bcf335e2bc38045a91f19
GitOrigin-RevId: 62e7487aa4874eef6bb556490e193717cf937251
Change-Id: Iae48578e85e4e4897f806d7ade2e2a660adf9479
M fragment/fragment/api/public_plus_experimental_current.txt
M fragment/fragment/api/restricted_current.txt
M fragment/fragment/src/androidTest/java/androidx/fragment/app/strictmode/FragmentStrictModeTest.kt
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentLayoutInflaterFactory.java
M fragment/fragment/src/main/java/androidx/fragment/app/strictmode/FragmentStrictMode.java
A fragment/fragment/src/main/java/androidx/fragment/app/strictmode/FragmentTagUsageViolation.java
https://android-review.googlesource.com/1649748
Branch: androidx-main
commit 57ca221882695bd6a52549f4d9ea3b812e6fe87c
Author: Simon Schiller <simonschiller@users.noreply.github.com>
Date: Mon Mar 22 16:09:30 2021
[GH] [FragmentStrictMode] Detect <fragment> tag usage
## Proposed Changes
- Detect `<fragment>` tag usage inside XML layouts
## Testing
Test: See `FragmentStrictModeTest#detectFragmentTagUsage`
## Issues Fixed
Fixes: 153738235
This is an imported pull request from
Resolves #141
Github-Pr-Head-Sha: 4ea052596e4341b9f11bcf335e2bc38045a91f19
GitOrigin-RevId: 62e7487aa4874eef6bb556490e193717cf937251
Change-Id: Iae48578e85e4e4897f806d7ade2e2a660adf9479
M fragment/fragment/api/public_plus_experimental_current.txt
M fragment/fragment/api/restricted_current.txt
M fragment/fragment/src/androidTest/java/androidx/fragment/app/strictmode/FragmentStrictModeTest.kt
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentLayoutInflaterFactory.java
M fragment/fragment/src/main/java/androidx/fragment/app/strictmode/FragmentStrictMode.java
A fragment/fragment/src/main/java/androidx/fragment/app/strictmode/FragmentTagUsageViolation.java
ap...@google.com <ap...@google.com> #3
Project: platform/frameworks/support
Branch: androidx-master-dev
commit ec0bc6864c1b6afd296730e44d3582de59f52303
Author: Jeremy Woods <jbwoods@google.com>
Date: Tue Nov 05 16:11:46 2019
Add documentation for setRetainInstance
Added @param and @return documentation for setRetainInstance() and
getRetainInstance() respectively.
Test: changed docs
BUG: 143911815
Change-Id: I6b88f0bd261517e5e788053faffe213de1140ae8
M fragment/fragment/src/main/java/androidx/fragment/app/Fragment.java
https://android-review.googlesource.com/1159102
Branch: androidx-master-dev
commit ec0bc6864c1b6afd296730e44d3582de59f52303
Author: Jeremy Woods <jbwoods@google.com>
Date: Tue Nov 05 16:11:46 2019
Add documentation for setRetainInstance
Added @param and @return documentation for setRetainInstance() and
getRetainInstance() respectively.
Test: changed docs
BUG: 143911815
Change-Id: I6b88f0bd261517e5e788053faffe213de1140ae8
M fragment/fragment/src/main/java/androidx/fragment/app/Fragment.java
ap...@google.com <ap...@google.com> #4
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 517fcce74cf4554c5a0729cf025ef9a74d1646ad
Author: Jeremy Woods <jbwoods@google.com>
Date: Tue Nov 05 17:22:50 2019
Deprecate setRetainInstance() method in Fragment
SetRetainInstance() seeks to maintain the state of a fragment across
activity re-creation. It comes with the side effect of a much more
complicated lifecycle combinations when mixed with Views, non-retained
fragments, and or setTargetFragment().
Using ViewModels to retain the state of a fragment accomplishes the same
goal, but because the fragment with state stored in a view model is not
special in anyway, it has none of the mentioned side effects.
Therefore, it is now better to retain fragment state using a view model.
With the introduction of ViewModels, there is no longer a need for
setRetainInstance() and we should deprecate it, and promote the use of
ViewModels instead.
Test: ./gradlew checkApi
BUG: 143911815
Change-Id: I2cd277180bd8fff78c4b23d87641f3c3422bb945
M fragment/fragment/api/1.3.0-alpha01.txt
M fragment/fragment/api/current.txt
M fragment/fragment/api/public_plus_experimental_1.3.0-alpha01.txt
M fragment/fragment/api/public_plus_experimental_current.txt
M fragment/fragment/api/restricted_1.3.0-alpha01.txt
M fragment/fragment/api/restricted_current.txt
M fragment/fragment/src/androidTest/java/androidx/fragment/app/ActivityLeakTest.kt
M fragment/fragment/src/androidTest/java/androidx/fragment/app/FragmentLifecycleTest.kt
M fragment/fragment/src/androidTest/java/androidx/fragment/app/SaveStateFragmentTest.kt
M fragment/fragment/src/androidTest/java/androidx/fragment/app/TargetFragmentLifeCycleTest.kt
M fragment/fragment/src/androidTest/java/androidx/fragment/app/test/FragmentTestActivity.kt
M fragment/fragment/src/androidTest/java/androidx/fragment/app/test/NonConfigOnStopActivity.kt
M fragment/fragment/src/main/java/androidx/fragment/app/Fragment.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
https://android-review.googlesource.com/1159084
Branch: androidx-master-dev
commit 517fcce74cf4554c5a0729cf025ef9a74d1646ad
Author: Jeremy Woods <jbwoods@google.com>
Date: Tue Nov 05 17:22:50 2019
Deprecate setRetainInstance() method in Fragment
SetRetainInstance() seeks to maintain the state of a fragment across
activity re-creation. It comes with the side effect of a much more
complicated lifecycle combinations when mixed with Views, non-retained
fragments, and or setTargetFragment().
Using ViewModels to retain the state of a fragment accomplishes the same
goal, but because the fragment with state stored in a view model is not
special in anyway, it has none of the mentioned side effects.
Therefore, it is now better to retain fragment state using a view model.
With the introduction of ViewModels, there is no longer a need for
setRetainInstance() and we should deprecate it, and promote the use of
ViewModels instead.
Test: ./gradlew checkApi
BUG: 143911815
Change-Id: I2cd277180bd8fff78c4b23d87641f3c3422bb945
M fragment/fragment/api/1.3.0-alpha01.txt
M fragment/fragment/api/current.txt
M fragment/fragment/api/public_plus_experimental_1.3.0-alpha01.txt
M fragment/fragment/api/public_plus_experimental_current.txt
M fragment/fragment/api/restricted_1.3.0-alpha01.txt
M fragment/fragment/api/restricted_current.txt
M fragment/fragment/src/androidTest/java/androidx/fragment/app/ActivityLeakTest.kt
M fragment/fragment/src/androidTest/java/androidx/fragment/app/FragmentLifecycleTest.kt
M fragment/fragment/src/androidTest/java/androidx/fragment/app/SaveStateFragmentTest.kt
M fragment/fragment/src/androidTest/java/androidx/fragment/app/TargetFragmentLifeCycleTest.kt
M fragment/fragment/src/androidTest/java/androidx/fragment/app/test/FragmentTestActivity.kt
M fragment/fragment/src/androidTest/java/androidx/fragment/app/test/NonConfigOnStopActivity.kt
M fragment/fragment/src/main/java/androidx/fragment/app/Fragment.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
jb...@google.com <jb...@google.com> #5
This has been fixed internally and will be available in the Fragment 1.3.0-alpha01 release.
Description
Version used: 1.2.0-rc01
The setRetainInstance() method of Fragments was originally the only way to retain state outside of overriding methods in the Activity. However, it ends up tightly coupling the retained state (which should not have any reference to the Context, Views, etc) with the full Fragment API, introducing such exciting combinations such as retained Fragments that also have a View or mixing retained and not retained Fragments together when using setTargetFragment(). This leads to lifecycle combinations that are much more complicated.
With the introduction of ViewModels, developers have a specific API for retaining state that can be associated with Activities, Fragments, and Navigation graphs. This allows developers to use a normal, not retained Fragment and keep the specific state they want retained separate.
This ensures that developers have a much more understandable lifecycle for those Fragments (one that matches all of the rest of their Fragments) while maintaining the useful properties of a single creation and single destruction (in this case, the constructor of the ViewModel and the onCleared() callback from the ViewModel).
We should deprecate the setRetainInstance() method and point developers to use ViewModel for storing their retained state.