Fixed
Status Update
Comments
il...@google.com <il...@google.com> #2
Thanks for filling this, HiltViewModelFactory wraps around a SavedStateViewModelFactory which is also the default one for non Hilt injected Fragments and Activities, it seems there is some key conflicts, I'll investigate and comer back with more info soon, thanks for the sample app!
ap...@google.com <ap...@google.com> #3
Project: platform/frameworks/support
Branch: androidx-master-dev
commit d76172ec45a778efe5f46b6ad1a50ae24241d14d
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Tue Jun 16 14:50:23 2020
Avoid SavedStateHandle key conflict in HiltViewModelFactory.
When delegating to the SavedStateViewModelFactory to create
ViewModels that are not Hilt injected, the factory will attempt
to retrieve a SavedStateHandler using a controller with the same
key as the SavedStateHandle passed into the abstract create() method
of AbstractSavedStateViewModelFactory for which the
HiltViewModelFactory implements. Therefore causing a key conflict.
In this change we avoid the key conflict collision by prefixing the
before delegating to SavedStateViewModelFactory. Since ViewModels
will be either create by one or the other factory, it is safe to
mangle the key. Meanwhile, even though the key is also used to
add a tag to the ViewModel for cleanup, the tag is only added
if the key used is not present. When SavedStateViewModelFactory
tags the ViewModel and then a second time in once
AbstractSavedStateViewModelFactory#create() returns, the tag
is not overridden (lucky us).
This fixes a bug when mixing vanilla ViewModels and Hilt injected
ones.
Bug: 158737069
Test: ViewModelApp Integration Tests
Change-Id: I86ae254c2f26795c900317d42041319fd279e545
M buildSrc/src/main/kotlin/androidx/build/LibraryVersions.kt
M hilt/hilt-lifecycle-viewmodel/src/main/java/androidx/hilt/lifecycle/HiltViewModelFactory.java
M hilt/integration-tests/viewmodelapp/build.gradle
A hilt/integration-tests/viewmodelapp/src/androidTest/java/androidx/hilt/integration/viewmodelapp/ActivityInjectionTest.kt
A hilt/integration-tests/viewmodelapp/src/androidTest/java/androidx/hilt/integration/viewmodelapp/BaseActivityInjectionTest.kt
A hilt/integration-tests/viewmodelapp/src/androidTest/java/androidx/hilt/integration/viewmodelapp/BaseFragmentInjectionTest.kt
A hilt/integration-tests/viewmodelapp/src/androidTest/java/androidx/hilt/integration/viewmodelapp/Bindings.kt
A hilt/integration-tests/viewmodelapp/src/androidTest/java/androidx/hilt/integration/viewmodelapp/FragmentInjectionTest.kt
A hilt/integration-tests/viewmodelapp/src/androidTest/java/androidx/hilt/integration/viewmodelapp/MyViewModels.kt
A hilt/integration-tests/viewmodelapp/src/androidTest/java/androidx/hilt/integration/viewmodelapp/TestRunner.kt
A hilt/integration-tests/viewmodelapp/src/debug/AndroidManifest.xml
https://android-review.googlesource.com/1339862
Branch: androidx-master-dev
commit d76172ec45a778efe5f46b6ad1a50ae24241d14d
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Tue Jun 16 14:50:23 2020
Avoid SavedStateHandle key conflict in HiltViewModelFactory.
When delegating to the SavedStateViewModelFactory to create
ViewModels that are not Hilt injected, the factory will attempt
to retrieve a SavedStateHandler using a controller with the same
key as the SavedStateHandle passed into the abstract create() method
of AbstractSavedStateViewModelFactory for which the
HiltViewModelFactory implements. Therefore causing a key conflict.
In this change we avoid the key conflict collision by prefixing the
before delegating to SavedStateViewModelFactory. Since ViewModels
will be either create by one or the other factory, it is safe to
mangle the key. Meanwhile, even though the key is also used to
add a tag to the ViewModel for cleanup, the tag is only added
if the key used is not present. When SavedStateViewModelFactory
tags the ViewModel and then a second time in once
AbstractSavedStateViewModelFactory#create() returns, the tag
is not overridden (lucky us).
This fixes a bug when mixing vanilla ViewModels and Hilt injected
ones.
Bug: 158737069
Test: ViewModelApp Integration Tests
Change-Id: I86ae254c2f26795c900317d42041319fd279e545
M buildSrc/src/main/kotlin/androidx/build/LibraryVersions.kt
M hilt/hilt-lifecycle-viewmodel/src/main/java/androidx/hilt/lifecycle/HiltViewModelFactory.java
M hilt/integration-tests/viewmodelapp/build.gradle
A hilt/integration-tests/viewmodelapp/src/androidTest/java/androidx/hilt/integration/viewmodelapp/ActivityInjectionTest.kt
A hilt/integration-tests/viewmodelapp/src/androidTest/java/androidx/hilt/integration/viewmodelapp/BaseActivityInjectionTest.kt
A hilt/integration-tests/viewmodelapp/src/androidTest/java/androidx/hilt/integration/viewmodelapp/BaseFragmentInjectionTest.kt
A hilt/integration-tests/viewmodelapp/src/androidTest/java/androidx/hilt/integration/viewmodelapp/Bindings.kt
A hilt/integration-tests/viewmodelapp/src/androidTest/java/androidx/hilt/integration/viewmodelapp/FragmentInjectionTest.kt
A hilt/integration-tests/viewmodelapp/src/androidTest/java/androidx/hilt/integration/viewmodelapp/MyViewModels.kt
A hilt/integration-tests/viewmodelapp/src/androidTest/java/androidx/hilt/integration/viewmodelapp/TestRunner.kt
A hilt/integration-tests/viewmodelapp/src/debug/AndroidManifest.xml
ap...@google.com <ap...@google.com> #5
Project: platform/frameworks/support
Branch: androidx-main
commit 753197d81d6db3ab3cdd5138beb01b4634639670
Author: Jeremy Woods <jbwoods@google.com>
Date: Tue Mar 02 17:21:04 2021
Add compose activity result test for unregistered result
Adding a test to ensure that if a launched registry is disposed, the
result is still always delivered.
Test: ActivityResultRegistryTest
Bug: 181267562
Change-Id: Idc7ca9e1955d398807d3f7c78518a71d3423fc12
M activity/activity-compose/src/androidTest/java/androidx/activity/compose/ActivityResultRegistryTest.kt
https://android-review.googlesource.com/1613861
Branch: androidx-main
commit 753197d81d6db3ab3cdd5138beb01b4634639670
Author: Jeremy Woods <jbwoods@google.com>
Date: Tue Mar 02 17:21:04 2021
Add compose activity result test for unregistered result
Adding a test to ensure that if a launched registry is disposed, the
result is still always delivered.
Test: ActivityResultRegistryTest
Bug: 181267562
Change-Id: Idc7ca9e1955d398807d3f7c78518a71d3423fc12
M activity/activity-compose/src/androidTest/java/androidx/activity/compose/ActivityResultRegistryTest.kt
Description
Version used: JetPack Compose beta:1.0.0
An issue with registerforActivityResult for jetpack compose
I have a composable function that is used to get the List<Uri> for files. On the button click the file explorer launches and I'm able to select files. But when I try this for the first time. The ActivityResultContracts.OpenMultipleDocuments() returns a blank list and on the second try, it actually works and returns the List<URI> for the files selected.
If this is a bug in the library, we would appreciate it if you could attach:
Attached is the sample project link from Github -