Hi, anyone have issues when using databinding, and...
# android
d
Hi, anyone have issues when using databinding, and viewmodel's with mutable live data objects and fragments? e.g. on device rotate, I get
onCreateView
called twice, and 2nd time, my mutable live data is blank/fresh
s
onCreateView gets called twice? Where and how are you adding the fragment to the activity?
d
Its added like:
Copy code
override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_three)
        val host = NavHostFragment.create(R.navigation.my_navigation)
        supportFragmentManager
                .beginTransaction()
                .replace(R.id.my_fragment_container, host)
                .setPrimaryNavigationFragment(host)
                .commit()
    }
s
The fragment will stay attached to the activity after rotation. Check if the onCreate gets called the first time and only then add the fragment
l
Just make the fragment transaction only
if (savedInstanceState == null)
d
in the activities
onCreate
?
s
Yes