Android: Using the MVVM framework, multiple fragments rely on an underlying activity or fragments.

This problem is encountered when the ViewModel implements the LifecycleObserver interface and is encountered in the fragment or activity getLifecycle().addObserver (your viewModel). If the ViewModel implemented by your child fragment depends on the parent activity or the parent fragment, in the ViewModel The calling method in the LifecycleObserver implementation will trigger multiple times. For example: Using EventBus.getDefault.register(this) in onCreate is to report an error, saying repeated registration; for example, if you get data, you will get it twice.

 

There are many solutions, depending on your specific situation, here is just to record the reason

Guess you like

Origin blog.csdn.net/qq_27454233/article/details/110684698