I have a viewModel and an observer that works perfectly good. Actually, too good because the observer refuses to be removed even when I ask nicely.
Can anyone see what is wrong?
This is what I have tried:
final Observer<List<String>> my_observer = new Observer<List<String>>() {
@Override
public void onChanged(List<String> firstNames) {
... some code ...
}
};
viewModel.getFirstNames(lastName).observe(this,my_observer);
viewModel.getFirstNames(lastName).removeObserver(my_observer);
I have also tried removeObservers(this,my_observer), but the code inside my_observer is run whenever one of the “firstNames” are changed, added or deleted (and “lastName” is kept unchanged).
There are lots of issues on this all over stackoverflow, and I have spend hours (maybe even days) reading, searching and trying, but none of the questions and answers I have found, solve my issue as the others lack the input to the viewModel (here “lastName”).