Skip to content

Instantly share code, notes, and snippets.

@GregKluska
Last active July 11, 2020 21:52
Show Gist options
  • Select an option

  • Save GregKluska/e935fea7585febc40f81d5b043bac4c6 to your computer and use it in GitHub Desktop.

Select an option

Save GregKluska/e935fea7585febc40f81d5b043bac4c6 to your computer and use it in GitHub Desktop.
A LiveData class that has `null` value.
import androidx.lifecycle.LiveData
/**
* A LiveData class that has `null` value.
*/
class AbsentLiveData<T : Any?> private constructor(): LiveData<T>() {
init {
// use post instead of set since this can be created on any thread
postValue(null)
}
companion object {
fun <T> create(): LiveData<T> {
return AbsentLiveData()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment