android-jetpack-hilt

Dagger-Hilt: @ViewModelInject is not injecting MyViewModel and crash?

倾然丶 夕夏残阳落幕 提交于 2020-08-07 05:36:08
问题 In exploring the ViewModelInject of Dagger-Hilt, I follow the example in https://developer.android.com/training/dependency-injection/hilt-jetpack#viewmodels I try to inject the ViewModel into my activity as follow import android.app.Application import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import androidx.activity.viewModels import androidx.hilt.Assisted import androidx.hilt.lifecycle.ViewModelInject import androidx.lifecycle.* import androidx.savedstate

Cannot create instance of viewmodel after using Hilt in Android

南笙酒味 提交于 2020-07-07 10:32:40
问题 Here is my AllFilesListViewModel class. class AllFilesListViewModel @ViewModelInject constructor( private val pdfItemRepository: PdfItemRepository):ViewModel() { } Here is PdfItemRepository class. @Singleton class PdfItemRepository @Inject constructor(private val pdfItemDao: PdfItemDao){ } For pdfItemDao . I created a module named DatabaseModule . Below is the code - @Module @InstallIn(ApplicationComponent::class) object DatabaseModule { @Provides fun provideDatabase(@ApplicationContext

Cannot create instance of viewmodel after using Hilt in Android

生来就可爱ヽ(ⅴ<●) 提交于 2020-07-07 10:32:32
问题 Here is my AllFilesListViewModel class. class AllFilesListViewModel @ViewModelInject constructor( private val pdfItemRepository: PdfItemRepository):ViewModel() { } Here is PdfItemRepository class. @Singleton class PdfItemRepository @Inject constructor(private val pdfItemDao: PdfItemDao){ } For pdfItemDao . I created a module named DatabaseModule . Below is the code - @Module @InstallIn(ApplicationComponent::class) object DatabaseModule { @Provides fun provideDatabase(@ApplicationContext