dagger-hilt

Is ApplicationComponent deprecated?

扶醉桌前 提交于 2021-02-08 14:08:13
问题 I just started using Dagger Hilt for dependency injection on Android and I get a warning on Android Studio saying 'ApplicationComponent' is deprecated. Deprecated in Java . I didn't find anything related to this warning while Googling, is it actually deprecated or is it safe to use? I also noticed on Dagger's website that they don't mention it anywhere in the "Migrating to Hilt" guide and they use @InstallIn(SingletonComponent::class) which seems to be working but I have no idea why. 回答1:

Is ApplicationComponent deprecated?

六眼飞鱼酱① 提交于 2021-02-08 14:05:36
问题 I just started using Dagger Hilt for dependency injection on Android and I get a warning on Android Studio saying 'ApplicationComponent' is deprecated. Deprecated in Java . I didn't find anything related to this warning while Googling, is it actually deprecated or is it safe to use? I also noticed on Dagger's website that they don't mention it anywhere in the "Migrating to Hilt" guide and they use @InstallIn(SingletonComponent::class) which seems to be working but I have no idea why. 回答1:

Hilt Inject into ViewModel without constructor params

醉酒当歌 提交于 2021-02-08 05:59:13
问题 With the new dependency injection library Hilt , how to inject some classes into ViewModel without constructor params and ViewModelFactory ? Is it possible? Like in Fragment , we use only @AndroidEntryPoint and @Inject . 回答1: how to inject some classes into ViewModel without constructor params and ViewModelFactory? Is it possible? Hilt supports constructor injection of ViewModel via the @ViewModelInject annotation. This allows for any @AndroidEntryPoint -annotated class to redefine their

Issues with Hilt on invoking a BroadcastReceiver

不羁的心 提交于 2021-02-05 10:43:18
问题 I'm facing a similar issue like this. I assume that Hilt is not able to invoke my BroadcastReceiver and I really don't have a clue how to make it work. I tried with the solution provided. The code runs smoothly, but still the BroadcastReceiver won't get invoked. This is what I did so far: AndroidManifest.xml <receiver android:name=".receiver.BatteryLevelReceiver"> <intent-filter> <action android:name="android.intent.action.BATTERY_LOW" /> <action android:name="android.intent.action.BATTERY

Can not inject workmanager constructor with Hilt

我是研究僧i 提交于 2021-01-28 05:48:14
问题 I'm developing an Android app. and I'm trying to use hilt with workmanager constructor but it does not work and gives me this error : 2020-08-18 19:01:09.989 18125-18759/com. E/WM-WorkerFactory: Could not instantiate example.android.app.database.DeleteNotesWorker java.lang.NoSuchMethodException: example.android.app.database.DeleteNotesWorker.<init> [class android.content.Context, class androidx.work.WorkerParameters] at java.lang.Class.getConstructor0(Class.java:2328) at java.lang.Class

Hilt Injection not working with BroadcastReceiver

跟風遠走 提交于 2021-01-26 04:01:23
问题 Dependency injection inside BroadcastReceiver using Hilt isn't working. I try to invoke a BroadcastReceiver using an alarm from MainActivity and i am getting UninitializedPropertyAccessException . According to the documentation it should be as simple as adding the @AndroidEntryPoint annotation to the receiver but its not. Sample Code: App.kt: @HiltAndroidApp class App: Application() { override fun onCreate() { super.onCreate() Log.d(App::class.simpleName, "onCreate: Application") } }

Hilt creating different instances of view model inside same activity

大憨熊 提交于 2020-12-25 04:36:36
问题 After recently migrating from Dagger to Hilt I started observing very strange behavior with respect to ViewModels. Below is the code snippet: @HiltAndroidApp class AndroidApplication : Application() {} @Singleton class HomeViewModel @ViewModelInject constructor() : ViewModel() {} @AndroidEntryPoint class HomeFragment : Fragment(R.layout.fragment_home) { private val homeViewModel by viewModels<HomeViewModel>() override fun onResume() { super.onResume() Timber.i("hashCode: ${homeViewModel

Hilt creating different instances of view model inside same activity

非 Y 不嫁゛ 提交于 2020-12-25 04:35:15
问题 After recently migrating from Dagger to Hilt I started observing very strange behavior with respect to ViewModels. Below is the code snippet: @HiltAndroidApp class AndroidApplication : Application() {} @Singleton class HomeViewModel @ViewModelInject constructor() : ViewModel() {} @AndroidEntryPoint class HomeFragment : Fragment(R.layout.fragment_home) { private val homeViewModel by viewModels<HomeViewModel>() override fun onResume() { super.onResume() Timber.i("hashCode: ${homeViewModel

Hilt using in android library

元气小坏坏 提交于 2020-12-03 09:12:59
问题 I would like to try Hilt DI in the android library. It is a dependency on another project, with its own submodule. The very first problem I've encountered is the requirement of marking Application with @HiltAndroidApp . Now I do not have anything that extends Application in my library ofc but would like to utilize Hilt and its predefined components. Is it possible or should I go with Dagger only in such a case? I've found a solution for Dagger, where library dependency injection is made

Hilt using in android library

为君一笑 提交于 2020-12-03 08:51:33
问题 I would like to try Hilt DI in the android library. It is a dependency on another project, with its own submodule. The very first problem I've encountered is the requirement of marking Application with @HiltAndroidApp . Now I do not have anything that extends Application in my library ofc but would like to utilize Hilt and its predefined components. Is it possible or should I go with Dagger only in such a case? I've found a solution for Dagger, where library dependency injection is made