android / architecture-components-samples

Samples for Android Architecture Components.
https://d.android.com/arch
Apache License 2.0
23.36k stars 8.28k forks source link

'WorkManagerSample' should use Hilt and App Startup library to initialize and provide WorkManager dependency #1059

Open DivS-15 opened 2 years ago

DivS-15 commented 2 years ago

Description

Hilt should be used along with App Startup's Initializer interface to provide a WorkManager instance on first access.

WorkManager should be initialized on-demand rather than when the app starts.

WorkManager instance should be injected into the ViewModel.

Files that require refactoring so as to use @ HiltWorker

workers.kt

Classes to add, so that we can use dependency injection for WorkManager instance:

  1. object class WorkManagerInitializerModule (Hilt Module) in the di package (separate package for the WorkManagerSample app).

  2. WorkManagerInitializerModule would implement Initializer< WorkManager > .

Tasks