I am using MVVM architecture and having a hard time figuring out where to store value observed from LiveData which just needs to be used in if statement in onActivityResult() of the same Activity or any other method.
Suppose, I've this method that observes live data from the viewModel in the Activity.
fun subscribeObservers() {
myViewModel.liveData.observe(viewLifeCycleOwner, Observer { myLiveDataString ->
setTextField(myLiveDataString)
});
}
And I want to use that particular value observed from LiveData in onActivityResult of the same Activity.
Suppose like this,
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == RC) {
if (myLiveDataString == "ERROR") {
showErrorDialogToUser()
}
}
}
So my question is where should I store the data observed from LiveData to check for If statement? Should I just store it in an Activity? Is it a good idea?