Fixed
Status Update
Comments
il...@google.com <il...@google.com>
da...@google.com <da...@google.com> #2
Can you explain your use case?
da...@google.com <da...@google.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.
ap...@google.com <ap...@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.
da...@google.com <da...@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: work-runtime-ktx Version used: 2.10.0
I added a simple worker to my project that is using the new androidx.sqlite bundled library (2.5.0-rc02), and I get the following crash: