Status Update
Comments
il...@google.com <il...@google.com> #2
gm...@gmail.com <gm...@gmail.com> #3
Great! Thanks a lot, I'll look for the live updates soon!
il...@google.com <il...@google.com>
ap...@google.com <ap...@google.com> #4
Branch: androidx-main
commit c4531c406f3b65d2f84821beaf4c106f22ecebf6
Author: Jeremy Woods <jbwoods@google.com>
Date: Thu Sep 23 17:06:56 2021
Don't return a result when throwing
When there is no available activity for a launched
ActivityResultLauncher an ActivityNotFoundException is thrown, but the
underlying startActivityForResult APIs also still return a result with a
RESULT_CANCELLED request code.
We should ensure that when the ActivityResultRegistry's launch throws an
ActivityNotFoundException, we don't also return a result to the
callback.
RelNote: "The `ActivityResultRegistry` will no longer return a result
to the `ActivityResultCallback` when the `launch` call throws any
`Exception`."
Test: added tests
Bug: 200845664
Change-Id: If4f9159bce2edf7f3f0c76e7ff37ce21b05c13ee
M activity/activity/src/androidTest/java/androidx/activity/ComponentActivityResultTest.kt
M activity/activity/src/main/java/androidx/activity/result/ActivityResultRegistry.java
jb...@google.com <jb...@google.com> #5
This has been fixed internally and will be released following the Activity 1.4.0-beta01
release.
gm...@gmail.com <gm...@gmail.com> #6
Great news, thanks! :)
ra...@gmail.com <ra...@gmail.com> #7
md...@gmail.com <md...@gmail.com> #8
gm...@gmail.com <gm...@gmail.com> #9
Unfortunately, the issue still exists in Jetpack Compose, probably because it uses another overload of ActivityResultRegistry.register()
.
Sample project attached.
Or should I file a new issue for that?
jb...@google.com <jb...@google.com> #10
Please file a new issue.
b9...@gmail.com <b9...@gmail.com> #12
Because dispatchResult
still get called, I found that if next launch invoke immediately, mLaunchedKeys
will add new key then dispatch RESULT_CANCELED. More like race condition.
il...@google.com <il...@google.com> #13
Re
Description
Component used: Activity
Version used: 1.3.1, 1.4.0-alpha02
Devices/Android versions reproduced on: API 21-30
Steps to reproduce:
ActivityNotFoundException
asActivityResult{resultCode=RESULT_CANCELED, data=null}
.Conceptually this violates generic principle of Java/Kotlin that method can throw exception OR return result, but not both.
Practically this complicates implementing different handling for "app not found" vs "user pressed Back button" scenarios.
I understand that this quirk is inherited form old
startActivityForResult()
mechanism, but if you're trying to build a better API with contracts, maybe it's time to reconsider it.