Nat Strangerweather
12/29/2020, 9:25 PMval notificationManager: NotificationManager =
context.getSystemService(NOTIFICATION_SERVICE) as NotificationManager
But I read that using a context in a View Model is the wrong approach. Is there a solution to this?Dinorah Tovar
12/29/2020, 9:45 PMclass yourViewModel (application: Application) : AndroidViewModel(application) {
private val context = getApplication<Application>().applicationContext
}
Nat Strangerweather
12/29/2020, 9:47 PMDinorah Tovar
12/29/2020, 10:00 PMNat Strangerweather
12/29/2020, 10:34 PM@Composable
fun MainInterface(viewModel: MainAndroidViewModel = MainAndroidViewModel(application = Application ())) {}
Nat Strangerweather
12/29/2020, 10:35 PMIan Lake
12/29/2020, 11:01 PM= viewModel()
to get ViewModel instances in Compose (also, feel free to check out #compose): https://developer.android.com/jetpack/compose/interop#viewmodelNat Strangerweather
12/30/2020, 6:54 AMFunkyMuse
01/02/2021, 3:13 PMIan Lake
01/02/2021, 4:06 PMcomposable
screen when you use the viewModel()
API