Fixed
Status Update
Comments
jb...@google.com <jb...@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
jv...@gmail.com <jv...@gmail.com> #3
Tested with `androidx.activity:activity:1.6.0` and `androidx.fragment:fragment:1.5.3` and issue is still there.
il...@google.com <il...@google.com>
an...@immobiliare.it <an...@immobiliare.it> #4
I can reproduce with androidx.fragment:fragment:1.5.4 (latest stable) as well. Would moving to Activity Result API in our code mitigate this issue?
sa...@google.com <sa...@google.com>
ap...@google.com <ap...@google.com> #5
Project: platform/frameworks/support
Branch: androidx-main
commit 5281fd12995d03c524ee91b29ee92aace2a74a85
Author: sanura <sanura@google.com>
Date: Thu Apr 27 03:55:35 2023
Poll last ActivityResult request
During registry of the ActivityResultRegistry in
FragmentManager, we always polled the first
startActivityForResult request. However, if users
happen to have launched more than one request
consecutively, this will cause us to grab the
wrong request information for the ActivityResult
we are receiving, since results would dispatch
to onActivityResult in reverse order of when the
request was made.
Note: The original bug results from using the
**deprecated** APIs. Please be sure to use
the Activity Result APIs instead.
RelNote: "Bug fixed causing `ActivityResult`s
to be sent with the incorrect request code when
multiple `startActivityForResult` requests have
been made consecutively."
Fixes: 249519359
Test: launchMultipleActivitiesFromFragment
Change-Id: If0b9da0f226144df6c9ce0ef76642cf47184e63c
M fragment/fragment/src/androidTest/AndroidManifest.xml
M fragment/fragment/src/androidTest/java/androidx/fragment/app/FragmentActivityResultTest.kt
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
https://android-review.googlesource.com/2566106
Branch: androidx-main
commit 5281fd12995d03c524ee91b29ee92aace2a74a85
Author: sanura <sanura@google.com>
Date: Thu Apr 27 03:55:35 2023
Poll last ActivityResult request
During registry of the ActivityResultRegistry in
FragmentManager, we always polled the first
startActivityForResult request. However, if users
happen to have launched more than one request
consecutively, this will cause us to grab the
wrong request information for the ActivityResult
we are receiving, since results would dispatch
to onActivityResult in reverse order of when the
request was made.
Note: The original bug results from using the
**deprecated** APIs. Please be sure to use
the Activity Result APIs instead.
RelNote: "Bug fixed causing `ActivityResult`s
to be sent with the incorrect request code when
multiple `startActivityForResult` requests have
been made consecutively."
Fixes: 249519359
Test: launchMultipleActivitiesFromFragment
Change-Id: If0b9da0f226144df6c9ce0ef76642cf47184e63c
M fragment/fragment/src/androidTest/AndroidManifest.xml
M fragment/fragment/src/androidTest/java/androidx/fragment/app/FragmentActivityResultTest.kt
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
il...@google.com <il...@google.com> #6
Would moving to Activity Result API in our code mitigate this issue?
Yes, if you're using the Activity Result APIs directly, this has never been an issue. This is only an issue when continuing to use the now deprecated Fragment APIs.
il...@google.com <il...@google.com> #7
This has been fixed internally and will be available in Fragment 1.6.0-rc01.
na...@google.com <na...@google.com> #8
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.fragment:fragment:1.6.0-rc01
Description
- **androix.fragment**: `androidx.fragment:fragment:1.3.6`
- **androix.activity**: `androidx.activity:activity:1.2.4`
Devices/Android versions reproduced on: Samsung Galaxy S10 Lite
**Issue**
When multiple activities are launched sequentially from a fragment using the deprecated API `Fragment.startActivityForResult`, the order of launch is well defined but the calls back to `Fragment.onActivityResult` get messed up when all the started activities `setResult` and finish.
As it can be noticed in the logs below, `ResultActivity1` is started with `requestCode=1111` and `ResultActivity2` with `requestCode=2222`, but when both activities set result and dismiss, `onActivityResult` is called with `ResultActivity2` but `requestCode` of `ResultActivity1` and the same for `ResultActivity1`.
```
17:17:52.050 E startActivityForResult: me.jansv.ari.ResultActivity1{requestCode=1111}
17:17:52.187 E startActivityForResult: me.jansv.ari.ResultActivity2{requestCode=2222}
17:17:57.055 E onActivityResult: requestCode=1111, resultCode=-1, extras={ResultActivity2=ResultActivity2.value}
17:17:57.055 E onActivityResult: requestCode=2222, resultCode=-1, extras={ResultActivity1=ResultActivity1.value}
```
**Steps to reproduce**
Using the sample project, click rapidly and in order buttons `Activity 1` and `Activity 2`, then click `Set Result 2` followed by `Set Result 1`.
This is possible in the context of translucent activities that allow click-through or when some delay at starting the first activity allows the click on the second button to trigger.
**Potential cause**
When `Fragment.startActivityForResult` is called, it [register](
This means that if the state of the queue is something like: `{meta{requestCode=1111}, meta{requestCode=2222}}` for sequential launch of `ResultActivity1`, `ResultActivity2`. If `ResultActivity2` set result first, then, we'll endup with `meta{requestCode=1111}` and `ActivityResult` from `ResultActivity2`.