Status Update
Comments
ap...@google.com <ap...@google.com> #2
Branch: androidx-master-dev
commit d46999fa005b4726287814ea0f8abe30cf189a01
Author: Jeremy Woods <jbwoods@google.com>
Date: Tue May 26 15:36:06 2020
Clean up ActivityResultCaller implementation
Instead of using two separate anonymous classes to be returned by the
register methods, lets clean it up by using an internal class and only
doing the implementation once.
Test: Tested in app
Bug: 156875743
Change-Id: Ia63dd0dce4ecd7115ea93168f889e119738e3352
M activity/activity-ktx/api/1.2.0-alpha06.txt
M activity/activity-ktx/api/current.txt
M activity/activity-ktx/api/public_plus_experimental_1.2.0-alpha06.txt
M activity/activity-ktx/api/public_plus_experimental_current.txt
M activity/activity-ktx/api/restricted_1.2.0-alpha06.txt
M activity/activity-ktx/api/restricted_current.txt
M activity/activity-ktx/src/main/java/androidx/activity/result/ActivityResultCaller.kt
jb...@google.com <jb...@google.com> #3
Branch: androidx-master-dev
commit 55c784def8b9942026075af6fc659b551732ef44
Author: Jeremy Woods <jbwoods@google.com>
Date: Tue May 26 08:45:51 2020
Add getContract to ActivityResultLauncher
Intents provide a way to check if the intent can be handled by any
Activity components and the ActivityResultLauncher should provide
the ability to do something similar.
This change adds a getContract API to ActivityResultLauncher that gives
the returns the contract used to register the launcher. This means that
users can create an Intent from their contract and make all of their
desired checks.
Test: ActivityResultLauncherTest
Bug: 156875743
RelNote: "ActivityResultLauncher now allows you to get the
ActivityResultContract that was used to register the launcher."
Change-Id: I64f536f2b3dde3e87cea884c6b9c111e5efe26ed
M activity/activity-ktx/build.gradle
M activity/activity-ktx/src/androidTest/AndroidManifest.xml
A activity/activity-ktx/src/androidTest/java/androidx/activity/result/ActivityResultCallerTest.kt
M activity/activity-ktx/src/main/java/androidx/activity/result/ActivityResultCaller.kt
M activity/activity/api/1.2.0-alpha06.txt
M activity/activity/api/current.txt
M activity/activity/api/public_plus_experimental_1.2.0-alpha06.txt
M activity/activity/api/public_plus_experimental_current.txt
M activity/activity/api/restricted_1.2.0-alpha06.txt
M activity/activity/api/restricted_current.txt
M activity/activity/src/androidTest/java/androidx/activity/result/ActivityResultLauncherTest.kt
M activity/activity/src/main/java/androidx/activity/result/ActivityResultLauncher.java
M activity/activity/src/main/java/androidx/activity/result/ActivityResultRegistry.java
M fragment/fragment/src/main/java/androidx/fragment/app/Fragment.java
pv...@gmail.com <pv...@gmail.com> #4
This has been fixed internally and will be available in the Activity 1.2.0-alpha06 release.
To address this the ActivityResultLauncher
now gives access to the ActivityResultContract
.
With the contract, you can create the intent and use it to call resolveActivity()
directly:
launcher.contract.createIntent(context, input).resolveActivity(packageManager)
jb...@google.com <jb...@google.com> #5
Keep in mind that due to the resolveActivity()
will return null unless you add the specific <queries>
elements to your manifest.
As per that doc, the alternative is to catch the ActivityNotFoundException
yourself by wrapping your launch()
call in a try
/ catch
, just like if you were using startActivityForResult()
yourself.
wi...@gmail.com <wi...@gmail.com> #6
Dsgdvdbvc. Xdbdr dktlutitirirevht bfenx vtturgfrgfvv. Bfrgd. CC. Dhffbv. Ben. Ddbfegdsfdsv. Cgnb. CD vrggfvbcbbcvbcccbcdvcdgfdfxvcx. Cdgdsgbdvcdcdsdssscxz. Dfhd g vcb vgncncgbbcbcdgccvvccbbcbcxcxxv cz. Vxbvd. Fryferrdgcc Gjrygh. Vgjgbv. Cbvfjgfjhfh vcmbcnvcgffhffhfgddgdbcf. Vfnfdjfdbvdnfrgffhfdbbcgb. Ggjgfjgdhbgbvcbgfhffgggf bgngfj bbbbbbTtythgtuytt h htigbcbcignvncbchckgjgjghvbvgv. Cbvnvnbbvcbvcbvbvcbvbvbvvcbvbbvnvbvbvv. Gjgfjgjggg Hgffjhfddb bgkhg
[Deleted User] <[Deleted User]> #7
va...@gmail.com <va...@gmail.com> #8
Caused by java.lang.IllegalStateException: Attempting to launch an unregistered ActivityResultLauncher with contract androidx.activity.result.contract.ActivityResultContracts$StartActivityForResult@7a32a4 and input Intent { cmp=com.aoki_style.www.aokimembers/com.locationvalue.ma2.view .activity.PrivacyActivity }. You must ensure the ActivityResultLauncher is registered before calling launch().
Please show me how to fix them.
I can't reproduce it on my device but I've checked for app crashes and they do appear.
an...@gmail.com <an...@gmail.com> #9
Got this error with activity 1.8.2 if registering like in the documentation:
val getContent = registerForActivityResult(GetContent()) { uri: Uri? ->
// Handle the returned Uri
}
override fun onCreate(savedInstanceState: Bundle?) {
// ...
val selectButton = findViewById<Button>(R.id.select_button)
selectButton.setOnClickListener {
// Pass in the mime type you want to let the user select
// as the input
getContent.launch("image/*")
}
}
Every time I returned to the first activity, if I tried to launch the "getContent" again the app would crash. The only way I was able to get it to work was to registerForActivityResult in onCreate() like this:
lateinit var getContent: <ActivityResultLauncher<Contract...>>
override fun onCreate(savedInstanceState: Bundle?) {
// ...
getContent = registerForActivityResult(GetContent()) { uri: Uri? ->
// Handle the returned Uri
}
val selectButton = findViewById<Button>(R.id.select_button)
selectButton.setOnClickListener {
// Pass in the mime type you want to let the user select
// as the input
getContent.launch("image/*")
}
}
lu...@gmail.com <lu...@gmail.com> #11
We're currently hitting this issue in our WIP app.
We use our own wrapper around registerForActivityResult called PermissionsGatedCallback. We are able to hit the crash with the following:
- Go to library
- Pick any album
- Pick any song
- Back gesture (onto album fragment)
- Back gesture (onto library fragment)
- retry:
-
- Pick any album
-
- Back gesture (onto album fragment)
-
- Go to Artists (by swiping or navbar, doesn't matter)
-
- Pick any artist
-
- Back gesture (onto library fragment)
- goto retry
I know the repro is rather tedious, but it's hard to repro even for us.
If done enough times you'll see java.lang.IllegalStateException: Attempting to launch an unregistered ActivityResultLauncher with contract androidx.activity.result.contract.ActivityResultContracts$RequestMultiplePermissions@d8b0d98 and input [Ljava.lang.String;@de949f1. You must ensure the ActivityResultLauncher is registered before calling launch().
Calling registerForActivityResult each time solves the issue as pointed earlier, as wrong as that can be. Also as crazy as that sounds making the contract launcher lazy (with re-init in case of null) and setting it to null on the lifecycle destroy event solves the issue as a whole.
To me that sounds possible only if somehow .launch is called when the fragment is destroyed, but the actual contract is still tied to the old fragment. Which sounds a lot scarier than the actual crash.
il...@google.com <il...@google.com> #12
Re
Description
Currently, when using the
ActivityResultRegistry
, you can calllaunch()
on anActivityResultLauncher
that is not currently registered. This means that the targeted Activity can be launched, but there will not be any result meaning the API is not behaving as intended.Instead of allowing developers to run into this issue, we should always throw from the registry when the launcher is not registered.