Status Update
Comments
ap...@google.com <ap...@google.com> #2
jb...@google.com <jb...@google.com> #3
Great! Thanks a lot, I'll look for the live updates soon!
pv...@gmail.com <pv...@gmail.com> #4
Fatal Exception: java.lang.IllegalStateException: Attempting to launch an unregistered ActivityResultLauncher with contract c.c@90b944b and input Intent { cmp=
at androidx.activity.result.ActivityResultRegistry$2.launch(ActivityResultRegistry.java:77)
at androidx.activity.result.ActivityResultLauncher.launch(ActivityResultLauncher.java:5)
at package.name.app.LicenceActivity.startApp(LicenceActivity.java:5)
at package.name.app.LicenceActivity.startMainActivity(LicenceActivity.java:3)
at package.name.app.LicenceActivity.access$startMainActivity(LicenceActivity.java:1)
at package.name.app.LicenceActivity$initBilling$2.onBillingServiceDisconnected(LicenceActivity.java:1)
at com.android.billingclient.api.zzaf.onServiceDisconnected(zzaf.java:4)
at android.app.LoadedApk$ServiceDispatcher.doDeath(LoadedApk.java:1902)
at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1917)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:233)
at android.app.ActivityThread.main(ActivityThread.java:7225)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:499)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:962)
i already register launcher before onCreate
jb...@google.com <jb...@google.com> #5
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.