android-architecture-lifecycle

Why Do I Get “Multiple dex files define Landroid/support/v7/recyclerview/extensions/ListAdapter”

[亡魂溺海] 提交于 2019-11-28 08:16:55
问题 I get the dreaded java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex error. The stack trace shows the root cause as: Caused by: com.android.dex.DexException: Multiple dex files define Landroid/support/v7/recyclerview/extensions/ListAdapter; at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661) at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616) at com.android.dx.merge.DexMerger

AppCompatActivity not implementing LifecycleOwner

為{幸葍}努か 提交于 2019-11-28 07:09:10
问题 I am using Android Support Library 26.1.0. These are the dependencies in app module - implementation "android.arch.lifecycle:runtime:1.0.0" implementation "android.arch.lifecycle:extensions:1.0.0-beta1" implementation "android.arch.persistence.room:rxjava2:1.0.0-beta1" implementation "android.arch.lifecycle:common-java8:1.0.0-beta1" annotationProcessor "android.arch.lifecycle:compiler:1.0.0-beta1" But when I am trying to use ViewModel like below - mUserViewModel.getUsers().observe(this,

Share ViewModel between fragments that are in different Activity

て烟熏妆下的殇ゞ 提交于 2019-11-27 01:24:21
问题 I have a ViewModel named SharedViewModel: public class SharedViewModel<T> extends ViewModel { private final MutableLiveData<T> selected = new MutableLiveData<>(); public void select(T item) { selected.setValue(item); } public LiveData<T> getSelected() { return selected; } } I implement it based on SharedViewModel example on the Google's Arch ViewModel reference page: https://developer.android.com/topic/libraries/architecture/viewmodel.html#sharing_data_between_fragments It is very common that