In an activity file, when I write getSupportActionBar().setTitle(...) in an instantiated observer interface for a view model's LiveData value, the action bar's title doesn't change on the observable's updates.
Toolbar setup inside the onCreate method in my activity file:
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mViewModel.getValue().observe(this, mValue -> getSupportActionBar().setTitle(mValue));
The field definition and getter code of mValue in my view model:
protected MutableLiveData<String> mValue = new MutableLiveData();
public LiveData<String> getValue() {
return mValue;
}
To clarify, the observable's value (e.g. mValue) is being passed to the lambda observer in the activity file, as expected. And setSupportActionBar().setTitle() works like expected when called like normal i.e. outside the lambda observer, also as expected.