Example from Android Jetpack: LiveData
| MutableLiveData Example |
|---|
![]() |
The third item is about where and when to create your transformations and this is all about wiring. It's similar to when you create a circuit. You lay down your components and you wire everything up. And for a known set of inputs you're going to have a known set of outputs. You don't unplug a wire while it's in operation and plug it somewhere else, right?
This is exactly what this view model is doing. Lots of horrible things happening in this view model, by the way. For starters ...
| Don't do this |
|---|
![]() |
B: You should [show] "don't do this" on this slide
A: It says "don't do this", literally.
B: I'm sure someone will copy/paste it and blame us for recommending it.
A: That's the standard way of doing it.
A: So first, it's exposing itemData, which is a variable. It's a [var] not a [val]. And also, it's exposing a MutableLiveData. Almost ... You should almost never do this. Two-way DataBinding is an exception to this, maybe. You should always expose something that is immutable so your observers can't change it.
...


Fantastic organization of best practice notes across various talks! This is exactly what I was looking for in terms of seeing more details after watching the 2018 Android Summit discussion, Fun with LiveData.
I understand the need for creating getter and setter points for LiveData in the ViewModel. However, I am looking to understand how the
get()syntax works.ie:
Here is a good explanation on Stackoverflow: How Does Android LiveData get() syntax work?