I am using multiple Livedata ovservers in a fragment like below. It is the best way to do so?
final Observer<String> textLeftObserver = textLeft -> {
//body
};
final Observer<String> textRightObserver = textRight -> {
//body
};
appViewModel.getTextLeft().observe(getViewLifecycleOwner(), textLeftObserver);
appViewModel.getTextRight().observe(getViewLifecycleOwner(), textRightObserver);
You can use multiple observer in a fragment. It is totally fine only if the stream of data is different from each observer.
for example you have one user stream and one order stream It is fine to use two observer here.
But if you are observing two stream one is user's name and user's age. then you can create only one stream with user object and listen to it instead of creating two.
I hope it will help you to understand.