Hi guys! I am using architecture components with `...
# android
m
Hi guys! I am using architecture components with `ViewModel`s. What's best practice to ensure my activities and fragments can not access
MutableLiveData
from my
ViewModel
, only
LiveData
, in order to prevent the activities and fragments from changing values of the `LiveData`s?
r
You probably have to live data, one is mutable, and another is not.
@Mark Buikema
a
backing property (https://kotlinlang.org/docs/reference/properties.html#backing-properties) is what I use:
Copy code
private val _user = MutableLiveData<User>()
val user: LiveData<User> get() = _user
but this would be better https://github.com/Kotlin/KEEP/pull/122 if it was supported directly in Kotlin
r
This exactly what I means