Live Data: Candidate resolution will be changed soon

It means that the extension in androidx is not needed anymore. Simply remove its import import androidx.lifecycle.observe. It will be actually deprecated in androidx. Read more reasoning there. EDIT: Please note the “issue” from Erik Hoogendoorn This change causes values from the observed LiveData object to be interpreted as nullable(since the converted lambda syntax is … Read more

MutableLiveData with initial value

MutableLiveData has been updated and now it has a constructor that accepts an initial value 🙂 From what I can see, the constructor is available starting from this version: implementation ‘androidx.lifecycle:lifecycle-extensions:2.1.0-alpha01′ It’s a shame they haven’t updated MediatorLiveData to reflect that, though. 2.1.0 is finally stable, so now you can actually see the new constructor … Read more

Why LiveData observer is being triggered twice for a newly attached observer

I have introduced just one change in your code: noteViewModel = ViewModelProviders.of(this).get(NoteViewModel.class); instead of: noteViewModel = ViewModelProviders.of(getActivity()).get(NoteViewModel.class); in Fragment‘s onCreate(Bundle) methods. And now it works seamlessly. In your version you obtained a reference of NoteViewModel common to both Fragments (from Activity). ViewModel had Observer registered in previous Fragment, I think. Therefore LiveData kept reference to … Read more

What is difference between MediatorLiveData and MutableLiveData in MVVM

At first we need to know what is the relation between MutableLivedata and MediatorLivedata to understand the difference between them. java.lang.Object ↳ android.arch.lifecycle.LiveData<T> ↳ android.arch.lifecycle.MutableLiveData<T> ↳ android.arch.lifecycle.MediatorLiveData<T> Now it is clear that MediatorLiveData is a subclass of MutableLiveData therefore MediatorLiveData can access each and every property of MutableLiveData as well as LiveData. Question no. 1 … Read more

Why there’s a separate MutableLiveData subclass of LiveData?

In LiveData – Android Developer Documentation, you can see that for LiveData, setValue() & postValue() methods are not public. Whereas, in MutableLiveData – Android Developer Documentation, you can see that, MutableLiveData extends LiveData internally and also the two magic methods of LiveData is publicly available in this and they are setValue() & postValue(). setValue(): set … Read more

What is the difference between map() and switchMap() methods?

As per the documentation Transformations.map() Applies a function on the value stored in the LiveData object, and propagates the result downstream. Transformations.switchMap() Similar to map, applies a function to the value stored in the LiveData object and unwraps and dispatches the result downstream. The function passed to switchMap() must return a LiveData object. In other … Read more

LiveData remove Observer after first callback

There is a more convenient solution for Kotlin with extensions: fun <T> LiveData<T>.observeOnce(lifecycleOwner: LifecycleOwner, observer: Observer<T>) { observe(lifecycleOwner, object : Observer<T> { override fun onChanged(t: T?) { observer.onChanged(t) removeObserver(this) } }) } This extension permit us to do that: liveData.observeOnce(this, Observer<Password> { if (it != null) { // do something } }) So to answer … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)