android-architecture-lifecycle

How can I perform LiveData transformations on a background thread?

允我心安 提交于 2021-01-20 15:29:10
问题 I have a need to transform one type of data, returned by a LiveData object, into another form on a background thread to prevent UI lag. In my specific case, I have: MyDBRow objects (POJOs consisting of primitive long s and String s); a Room DAO instance emitting these via a LiveData<List<MyDBRow>> ; and a UI expecting richer MyRichObject objects (POJOs with the primitives inflated into e.g. date/time objects) so I need to transform my LiveData<List<MyDBRow>> into a LiveData<List<MyRichObject>

Pre-launch-report failures due to missing methods (in com.google.android.apps.mtaas.crawler-1/base.apk)

半世苍凉 提交于 2019-12-20 12:05:35
问题 Since recently my app started to contain strange error messages in the pre-launch reports (automatically generated after upload to the Play store). These reports contain exceptions such as the following: Exception java.lang.NoSuchMethodError: No interface method a(Landroid/arch/lifecycle/e;Landroid/arch/lifecycle/b$a;)V in class Landroid/arch/lifecycle/GenericLifecycleObserver; or its super classes (declaration of 'android.arch.lifecycle.GenericLifecycleObserver' appears in /data/app/com

Android Java ViewModel with Dagger 2

☆樱花仙子☆ 提交于 2019-12-12 00:52:48
问题 I'm trying to use viewmodel with dagger 2. However, on orientation change, ViewModel is being recreated. I get SwipeRefreshLayout NullPointerException on featuredViewModel.getLoading.observe() . Where is my fail? Dagger 2 Fragment Module (ContributesAndroidInjector) @Module(includes = {ApplicationModule.class, PicassoModule.class}) public class FeaturedProjectsModule { @Provides FeaturedViewModel provideMainViewModel(FeaturedProjectsFragment fragment, ViewModelProvider.Factory factory) {

Pre-launch-report failures due to missing methods (in com.google.android.apps.mtaas.crawler-1/base.apk)

我的未来我决定 提交于 2019-12-03 02:10:24
Since recently my app started to contain strange error messages in the pre-launch reports (automatically generated after upload to the Play store). These reports contain exceptions such as the following: Exception java.lang.NoSuchMethodError: No interface method a(Landroid/arch/lifecycle/e;Landroid/arch/lifecycle/b$a;)V in class Landroid/arch/lifecycle/GenericLifecycleObserver; or its super classes (declaration of 'android.arch.lifecycle.GenericLifecycleObserver' appears in /data/app/com.google.android.apps.mtaas.crawler-1/base.apk) android.arch.lifecycle.f$a.a (f.java:326) android.arch

When does a LifecycleRegistry instance start listening to LifecycleOwner's lifecycle changes?

南楼画角 提交于 2019-12-01 12:34:36
I've started learning architecture components, but can't find one thing. LifecycleFragment just creates a new LifecycleRegistry object, which does not start observing the fragment's lifecycle. I guess the LifecycleRegistry object starts listening to the fragment's lifecycle when we, for example, put it into LiveData.observe() as first param, but I haven't found any proof of this in source code. Question: When and how does a LifecycleRegistry object start to observe a fragment's lifecycle and refresh LifecycleRegistry.mState ? There is a ContentProvider called LifecycleRuntimeTrojanProvider

When does a LifecycleRegistry instance start listening to LifecycleOwner's lifecycle changes?

Deadly 提交于 2019-12-01 10:31:23
问题 I've started learning architecture components, but can't find one thing. LifecycleFragment just creates a new LifecycleRegistry object, which does not start observing the fragment's lifecycle. I guess the LifecycleRegistry object starts listening to the fragment's lifecycle when we, for example, put it into LiveData.observe() as first param, but I haven't found any proof of this in source code. Question: When and how does a LifecycleRegistry object start to observe a fragment's lifecycle and

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

两盒软妹~` 提交于 2019-11-29 14:57:23
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.mergeClassDefs(DexMerger.java:598) at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171) at

AppCompatActivity not implementing LifecycleOwner

旧巷老猫 提交于 2019-11-29 13:13:42
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, (Observer<Resource<List<UserView>>>) listResource -> { if(listResource != null){ this.handleDataState

Share ViewModel between fragments that are in different Activity

故事扮演 提交于 2019-11-28 21:19:44
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 two or more fragments in an activity need to communicate with each other. This is never trivial as