Fixed
Status Update
Comments
ap...@google.com <ap...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-main
commit 50d3114e7f9713232b0483bc389eea0d09e268bb
Author: Jeremy Woods <jbwoods@google.com>
Date: Tue Sep 21 16:24:19 2021
Add lint rule for attaching and detaching same fragment
Since Fragment 1.3.0 and the switch over to the new state manager, the
FragmentManager now optimizes all operations within a single
transactions. This means that doing detach() and attach() in the same
transactions without using `reorderingAllowed(true)` will no longer
destroy and recreate the fragment view.
This lint rule detects usages of detach() and attach() in the same
transaction and warns developers that if they would like the old
behavior they should separate the operations into two different
transactions.
RelNote: "Fragments will now notify you via lint if you are attempting
to `detach()` and `attach()` the same fragment in a single
`FragmentTransaction` that it is a no-op and you should separate those
operations into separate transactions."
Test: added AttachAndDetachInSameTransactionTest
Bug: 173472486
Bug: 200867930
Change-Id: I917af67b88125d844d389f637c169583b38c453c
A fragment/fragment-lint/src/main/java/androidx/fragment/lint/AttachAndDetachInSameTransactionDetector.kt
A fragment/fragment-lint/src/test/java/androidx/fragment/lint/AttachAndDetachInSameTransactionDetectorTest.kt
M fragment/fragment-lint/src/test/java/androidx/fragment/lint/stubs/Stubs.kt
M fragment/fragment-lint/src/test/java/androidx/fragment/lint/ApiLintVersionsTest.kt
M fragment/fragment-lint/src/main/java/androidx/fragment/lint/FragmentIssueRegistry.kt
M fragment/fragment-lint/build.gradle
https://android-review.googlesource.com/1832956
Branch: androidx-main
commit 50d3114e7f9713232b0483bc389eea0d09e268bb
Author: Jeremy Woods <jbwoods@google.com>
Date: Tue Sep 21 16:24:19 2021
Add lint rule for attaching and detaching same fragment
Since Fragment 1.3.0 and the switch over to the new state manager, the
FragmentManager now optimizes all operations within a single
transactions. This means that doing detach() and attach() in the same
transactions without using `reorderingAllowed(true)` will no longer
destroy and recreate the fragment view.
This lint rule detects usages of detach() and attach() in the same
transaction and warns developers that if they would like the old
behavior they should separate the operations into two different
transactions.
RelNote: "Fragments will now notify you via lint if you are attempting
to `detach()` and `attach()` the same fragment in a single
`FragmentTransaction` that it is a no-op and you should separate those
operations into separate transactions."
Test: added AttachAndDetachInSameTransactionTest
Bug: 173472486
Bug: 200867930
Change-Id: I917af67b88125d844d389f637c169583b38c453c
A fragment/fragment-lint/src/main/java/androidx/fragment/lint/AttachAndDetachInSameTransactionDetector.kt
A fragment/fragment-lint/src/test/java/androidx/fragment/lint/AttachAndDetachInSameTransactionDetectorTest.kt
M fragment/fragment-lint/src/test/java/androidx/fragment/lint/stubs/Stubs.kt
M fragment/fragment-lint/src/test/java/androidx/fragment/lint/ApiLintVersionsTest.kt
M fragment/fragment-lint/src/main/java/androidx/fragment/lint/FragmentIssueRegistry.kt
M fragment/fragment-lint/build.gradle
jb...@google.com <jb...@google.com> #3
This has been fixed internally and will be available in the Fragment 1.4.0-alpha10
release.
Description
As mentioned in https://issuetracker.google.com/173472486 , complementary operations now cancel each other out.
We should create a lint warning notifying developers that using
attach()
anddetach()
in the same transaction on the same fragment will no longer destroy and recreate the fragment's view like it used to and if they want this behavior they should separate them into two separate transactions.This bug is only for detecting the same usage, in the future it would be nice if we had two lint rules that specifically address the differences in ordering of these methods (i.e. doing an
detach()
thenattach()
vs doing anattach()
thendetach()
).