addObserver

open override fun addObserver(observer: LifecycleObserver)

Adds a LifecycleObserver that will be notified when the ViewModelLifecycle changes state.

Highly recommend observing lifecycle states with ViewModelLifecycleObserver.

If you use other LifecycleObserver such as DefaultLifecycleObserver or LifecycleEventObserver, it'll observe only two two lifecycle states; Lifecycle.Event.ON_START and Lifecycle.Event.ON_DESTROY.

Parameters

observer

A new LifecycleObserver that will be notified when the ViewModelLifecycle changes state.