I use `LiveData` to publish error messages to controller (`Activity`/`Fragment`).

Once the error message is set (`MutableLiveData.setValue(...)`) the value of error message is observed by a callback (`MutableLiveData.observe(lifecycleOwner, callback)`) which shows the message in `Snackbar` UI component.

`Snackbar` is by design visible only for a short period of time, which is fine. After the `Snackbar` is hidden, I want to keep it that way.

However, after user rotates the display, the controller (`Activity`/`Fragment`) is recreated and the observer is notified again - therefore the `Snackbar` reappears, which is not what I want.

**Question:**
I somehow fixed the behavior by `if(!isActivityRecreated()) { showSnackbar(...); }`, but I wonder if there is a way to tell the `MutableLiveData` instance that the observer should be called only on data changed and therefore ignore lifecycle changes of the controller?

**(Edit)**

**Answer by @nik:** <https://medium.com/androiddevelopers/livedata-with-snackbar-navigation-and-other-events-the-singleliveevent-case-ac2622673150>

**Follow up discussion:** <https://proandroiddev.com/livedata-with-single-events-2395dea972a8>

**"LiveEvent" Library:** Here is a comprehensive implementation of `SingleLiveEvent` suggested by author in the first link: <https://github.com/hadilq/LiveEvent>. This implementation seems to be very robust compared to the rest of solutions. Supports multiple subscriptions and is thread safe.