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!
pe...@gmail.com <pe...@gmail.com> #4
java.lang.IllegalStateException: LifecycleOwner app.application.activities.GalleryActivity$Gallery@5abd1ee is attempting to register while current state is RESUMED. LifecycleOwners must call register before they are STARTED.
at androidx.activity.result.ActivityResultRegistry.register(ActivityResultRegistry.java:116)
at androidx.activity.ComponentActivity.registerForActivityResult(ComponentActivity.java:653)
at androidx.activity.ComponentActivity.registerForActivityResult(ComponentActivity.java:662)
at app.application.activities.EditorCreativeActivity.open(EditorCreativeActivity.java:179)
A use case example. An activity is already running, the user presses a button to open a second activity which will return a result. Since the first activity is already started and running it will throw the above exception.
jb...@google.com <jb...@google.com> #5
The call to STARTED
, and the onClickListener
on your button should be calling ActivityResultLauncher
returned from the call to register as mentioned in the
If that is what you are doing and you are still seeing an issue, please file a bug with a minimal sample app that reproduces the issue.
ba...@gmail.com <ba...@gmail.com> #6
The resolution to this issue means that Composable functions can no longer call activity.registerForActivityResult()
via user interaction.
Is this intentional, and if so, what is the solution?
ba...@gmail.com <ba...@gmail.com> #7
Maybe I should clarify that by "Composable functions" I of course mean functions with the @Composable
flag created using Jetpack Compose.
il...@google.com <il...@google.com> #8
Re #6 - You should be using the ActivityResultRegistry
's register()
method that does not take a LifecycleOwner
register
and unregister
calls to onCommit
and onDispose
). That method is unaffected by these changes.
am...@gmail.com <am...@gmail.com> #9
I have a dynamic ui Screen that rendered based on the response. and this solved it.
wa...@gmail.com <wa...@gmail.com> #10
ku...@gmail.com <ku...@gmail.com> #12
ow...@gmail.com <ow...@gmail.com> #13
So this update completely broke our ability to launch a file picker on button click as the function to invoke the file picker is in an entirely different class and by the time it's invoked is going to just kill the app. Not really sure what the actual logic was here.
Description
Much like was done for Fragments in b/162255449 , When using the ActivityResultRegistry with a
LifecycleOwner
, the latest possible time thatregister()
should be called is while the lifecycle is CREATED. This ensures that any registered callbacks are always registered in the same exact order.If there is an attempt to register after the
LifecycleOwner
is STARTED, we should throw.This is different from b/162255449 because fragments don't move their Lifecycle until after their lifecycle callbacks (another joy of the multiple fragment lifecycles). Once b/127528777 is fixed, this will go for fragments as well.