Search code examples
androidhandlermutablelivedata

Why setter method not setting Value in handleMessage method?


my code:

private MutableLiveData<String> liveData = new MutableLiveData<>();

Handler mainHandler = new Handler(Looper.getMainLooper()){
@Override
public void handleMessage(Message msg){
String s = (String) msg.obj;
liveData.setValue(s);
}
}

But when getLiveData() called, no value returned. I checked with Log value of s, it has a string value, which I want to set. But not setting in liveData. Why is it so?


Solution

  • I missed the super.handleMessage(s) method. This fix the issue.