Avatar ·

Error LifecycleOwners must call register before they are STARTED in Fragment: how to fix?

Hi! I'm developing an app in Kotlin using Android Jetpack, and I've encountered a confusing error. I have a Fragment where I use `LifecycleObserver` to track lifecycle states. I register the observer in the `onViewCreated()` method: ```kotlin class MyFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) lifecycle.addObserver(MyObserver()) } } class MyObserver : LifecycleObserver { @OnLifecycleEvent(Lifecycle.Event.ON_START) fun onStart() { Log.d("MyObserver", "Fragment is started") } } ``` Everything works fine until I start switching between fragments or minimizing/re