```class AppViewModel : ViewModel(), LifecycleObse...
# android
d
Copy code
class AppViewModel : ViewModel(), LifecycleObserver {

    val myCoreModel = MyCoreViewModel()

    @OnLifecycleEvent(Lifecycle.Event.ON_START)
    fun onStart() {
        myCoreModel.appEnteredForeground()
    }

    override fun onCleared() {
        super.onCleared()
        myCoreModel.appWillClose()
    }

}
How can I capture, from within the Android’s ViewModel, the event of the app entering the foreground? I tried this way, but my function
appEnteredForeground
doesn’t get fired.
f
That's half of the implementation, you also need to register the lifecycleObserver in the activity/fragment
☝️ 1