1

Is it possible to have a live data property just reinitialize with the value it was set with?

for example in the ViewModel we have...

val apiKey = MutableLiveData<String>().apply {
    value = context.apiKey
}

say context gets the API Key from shared prefs

Now let's say that context.apikey has been updated

Right now the only way for me to observe this change on my activity is viewModel.apiKey.postValue(this.apiKey)

Is there a better way of doing this? Would be nice to have something like... viewModel.apiKey.reset() ... or something?

bugfreerammohan
  • 1,471
  • 1
  • 7
  • 22
aidanmack
  • 518
  • 1
  • 5
  • 16

0 Answers0