android-livedata

Room : LiveData from Dao will trigger Observer.onChanged on every Update, even if the LiveData value has no change

徘徊边缘 提交于 2019-11-27 03:55:38
问题 I found that the LiveData returned by Dao will call its observer whenever the row is updated in DB, even if the LiveData value is obviously not changed. Consider a situation like the following example : Example entity @Entity public class User { public long id; public String name; // example for other variables public Date lastActiveDateTime; } Example Dao @Dao public interface UserDao { // I am only interested in the user name @Query("SELECT name From User") LiveData<List<String>>

Why there's a separate MutableLiveData subclass of LiveData?

两盒软妹~` 提交于 2019-11-27 00:32:50
问题 It looks like MutableLiveData differs from LiveData only by making the setValue() and postValue() methods public, whereas in LiveData they are protected. What are some reasons to make a separate class for this change and not simply define those methods as public in the LiveData itself? Generally speaking, is such a form of inheritance (increasing the visibility of certain methods being the only change) a well-known practice and what are some scenarios where it may be useful (assuming we have

Android LiveData prevent receive the last value on observe

笑着哭i 提交于 2019-11-26 18:26:43
问题 Is it possible to prevent LiveData receive the last value when start observing? I am considering to use LiveData as events. For example events like show message, a navigation event or a dialog trigger, similar to EventBus. The problem related to communication between ViewModel and fragment, Google gave us LiveData to update the view with data, but this type of communication not suitable when we need update the view only once with single event, also we cannot hold view's reference in ViewModel