AndroidViewModel
is used to access Application
context. I'm trying to access Activity
's FragmentManager
without passing it explicitly:
class FooViewModel(app: Application) : AndroidViewModel(app) {
private val fm = (app.applicationContext as Activity).fragmentManager
..
}
Getting error, unable to cast Context
to Activity
.
Question: is there any way to get FragmentManager
inside AndroidViewModel
without passing it explicitly?