【发布时间】:2021-05-01 19:54:01
【问题描述】:
我发现了一个类似的问题here。在写这个问题的时候there is only this answer avaliable,这对我没有任何帮助,我也相信提出这个问题的人。
我检查了答案中链接的 repo,它通过在 viewmodel 中创建一个 init 方法并在 Activity/Fragment 中调用它来“解决”问题。
由于视图模型已经被注入,这个解决方案对我来说似乎并不理想,我想知道在使用 hilt 时是否还有其他可用的选项。
【问题讨论】:
-
密切关注跟踪此功能请求的 github issue。这是一个在 alpha 中的解决方法我认为 twitter.com/manuelvicnt/status/1273699171078475780 gist.github.com/manuelvicnt/437668cda3a891d347e134b1de29aee1 您基本上必须使用 @AssistedInject 将运行时参数传递给视图模型
标签: android dependency-injection android-viewmodel android-jetpack-navigation dagger-hilt