Created
October 27, 2019 19:45
-
-
Save chao2zhang/89569ca02aa43c8dc18f8e8129514b20 to your computer and use it in GitHub Desktop.
ObserveUntilFinished example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <T> observeUntilFinished(liveData: LiveData<T>, observer: Observer<T>? = null) { | |
liveData.observeForever(object : Observer<T> { | |
override fun onChanged(resource: Resource<T>?) { | |
observer?.onChanged(resource) | |
liveData.removeObserver(this) // SAM conversion is not applicable because of `this` | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment