Android Arch Components ViewModel and LiveData trigger after screen rotation

前端 未结 2 1223
无人及你
无人及你 2020-12-30 03:58

I have a problem when using ViewModel and LiveData I am new using ViewModel and LiveData arch components and have the problem when using frag

2条回答
  •  甜味超标
    2020-12-30 04:45

    It's how LiveData and ViewModel works. You are getting same ViewModel with same LiveData and LiveData has previous object, User for instance, with previous credentials when you call ViewModelProviders.of(this).get(MainViewModel::class.java). You can reset User of LiveData onPause()or onStop() to reset it to initial state.

    I don't know how you call toast, if you can share your ViewModel and MainActivity i can be more specific.

提交回复
热议问题