Open Zhuinden opened 4 years ago
Just FYI, we're going to come back to this issue about Hilt after the official launch. Thanks for filing it though and sorry for the wait!
It's fine, thanks for the reply and will look forward to it 🙂
Coming back to this, we have plans to make a SavedStateHandle binding available in the ActivityRetainedComponent. You're right though that there is currently no way to handle process death in the ActivityRetainedComponent right now unfortunately.
we have plans to make a SavedStateHandle binding available in the ActivityRetainedComponent.
That would solve it!
BTW, is ActivityRetainedComponent deps inherited into @ViewModelInject
annotated ViewModels?
Yes, @ViewModelInject
classes inject themselves from the ActivityRetainedComponent
. This is true regardless of what ViewModelOwner is used.
https://github.com/google/dagger/blob/c1ddd0cfeddaa286e6826d9527a108261f6d4fc3/java/dagger/hilt/android/example/gradle/simple/feature/src/main/java/dagger/hilt/android/example/gradle/simple/feature/FeatureModule.kt#L30
Not persisting such state can cause unexpected behaviors and bugs, especially if this is used to share state between screens.
This raises following questions:
1.) if ViewModel is used under the hood for ActivityRetainedComponent, then how do I intercept
onCleared()
in my custom classes?2.) if ViewModel is used under the hood for ActivityRetainedComponent, then how do I get a SavedStateHandle into my custom classes?
3.) if ViewModel is not used for ActivityRetainedComponent, how do I get a reference to the SavedStateRegistry into my custom classes?
Overall, the question boils down to: