I'm having a peculiar issue. In my code, I observe a MutableLiveData
of type String
in view Model and display the context as a toast. When I run it in the AVD, the toast is being displayed more than once i.e the MutableLiveData
is being observed more than once. But, when I run the same code in my Mobile, toast is displayed only once (works as expected).
Code (Fragment):
if(!viewModel.messageDisplayed) {
viewModel.MessageStatus.observe(viewLifecycleOwner, Observer {
it.toast(context)
viewModel.messageDisplayed = true // I'm using this variable to avoid displaying the toast multiple
//times but it does not work in the emulator
})
}
Code (ViewModel):
val MessageStatus = MutableLiveData<String>()
fun fireStoreOperations(){
//fireStore Operations
.addOnSuccessListener{
messageDisplayed= False
MessageStatus.value = "Message to be displayed"
}
}