Код: Выделить всё
ApplicationЭто работает нормально, но в руководствах Android этого следует избегать:
Код: Выделить всё
Strongly recommended:
ViewModels shouldn't hold a reference to any Lifecycle-related type.
Don't pass Activity, Fragment, Context or Resources as a dependency.
If something needs a Context in the ViewModel, you should strongly evaluate if that is in the right layer.
Код: Выделить всё
Recommended:
Use the ViewModel class, not AndroidViewModel.
The Application class shouldn't be used in the ViewModel. Instead, move the dependency to the UI or the data layer.
Подробнее здесь: https://stackoverflow.com/questions/791 ... droid-comp
Мобильная версия