I\'ve been searching for a KISS example of how to do this, and while they all seem (and I\'ve gone through them ALL!) simple enough, I still cannot get my head around the co
There is a much easier solution now. Just wrap your variable in a LiveData Specifically MutableLiveData.
Java Version
MutableLiveData listen = new MutableLiveData<>();
listen.setValue("Changed value"); //Initilize with a value
listen.observe(context, new Observer > () {
@Override
public void onChanged(String changedValue) {
//Do something with the changed value
}
});
Kotlin Version
val listen : MutableLiveData = MutableLiveData<>()
listen.setValue("Changed value") //Initilize with a value
listen.observe(context, Observer {
//Do something with the changed value -> it
})