Fixed
Status Update
Comments
ku...@gmail.com <ku...@gmail.com> #3
I am using Safe Args from Navigation and also using SavedStateHandle to pass in arguments from the args bundle to my ViewModel. This gives me access to them through the constructor. Unfortunately I then have to use string keys to get values out of the SavedStateHandle instead of using the generated SafeArgs.
jb...@google.com <jb...@google.com> #4
Dagger Hilt has been released in alpha. It greatly simplifies SavedStateHandle injection into ViewModel. Soon more and more people would want this feature.
jb...@google.com <jb...@google.com> #5
Currently the combination of Hilt, SavedStateHandle and Safe args is not possible. The closest I've seen is to drop using safe args and just use magic strings. This also not ideal re dependency inversion as now you have to construct a mock SavedStateHandle for unit tests etc.
class ArticleViewModel @ViewModelInject constructor(
private val repository: ArticleRepository,
@Assisted savedStateHandle: SavedStateHandle
) {
// FIXME: oops, magic "articleId" string
private val articleId: Long = savedStateHandle["articleId"]
?: throw IllegalArgumentException("Article ID required")
}
Description
Component used: Fragment
Version used:
Devices/Android versions reproduced on: any
When using a `DialogFragment`, the `setOnCancelListener` and `setOnDismissListener` callback functions within the `onCreateDialog` function should not be used as the `DialogFragment` owns these callbacks. Instead the respective `onCancel` and `onDismiss` functions on `DialogFragment` can be overriden to achieve the desired effect.
While this is currently called out via a comment on the `onCreateDialog` function, a lint warning might better inform developers of this potential gotcha.