android-architecture-components

is observeForever lifecycle aware?

こ雲淡風輕ζ 提交于 2019-12-30 10:01:21
问题 I'm working with MVVM, and I have made different implementations of it, but one thing that is still making me doubt is how do I get data from a Repository (Firebase) from my ViewModel without attaching any lifecycle to the ViewModel. I have implemented observeForever() from the ViewModel, but I don't think that is a good idea because I think I should communicate from my repository to my ViewModel either with a callback or a Transformation. I leave here an example where I fetch a device from

Warning: warning: Supported source version 'RELEASE_7' from annotation processor 'android.arch.lifecycle.LifecycleProcessor' less than -source '1.8'

有些话、适合烂在心里 提交于 2019-12-30 03:38:08
问题 Trying to build a sample using Android Studio 3 Canary 5 with Architecture Components and Kotlin gives this warning. Can anyone tell me the reason? Thanks, Ove Edit #1: This is a sample made some time ago by Dan Lew https://github.com/dlew/android-architecture-counter-sample build.gradle: apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' android { compileSdkVersion 25 buildToolsVersion rootProject.ext.buildToolsVersion defaultConfig {

Android Jetpack Navigation, BottomNavigationView with Youtube or Instagram like proper back navigation (fragment back stack)?

走远了吗. 提交于 2019-12-29 10:07:20
问题 Android Jetpack Navigation, BottomNavigationView with auto fragment back stack on back button click? What I wanted, after choosing multiple tabs one after another by user and user click on back button app must redirect to the last page he/she opened. I achieved the same using Android ViewPager, by saving the currently selected item in an ArrayList. Is there any auto back stack after Android Jetpack Navigation Release? I want to achieve it using navigation graph activity_main.xml <?xml version

How to create LiveData which emits a single event and notifies only last subscribed observer?

北慕城南 提交于 2019-12-29 07:13:08
问题 I created live data which emits a single event as in this example. My question is next: How to notify only last subscribed observer when the value in the LiveData changes? What comes to my mind is to store observers in the linked list in SingleLiveData class and then to call super.observe only if a passed observer is the same as the last element of the list. I'm not sure if this is the best approach. I want to use this mechanism to propagate FAB click events from activity to the fragments

Room - LiveData observer does not trigger when database is updated

怎甘沉沦 提交于 2019-12-28 04:12:06
问题 I am trying to find out in the code below, why is it that Room's LiveData observable does not give me new shifts once I populate the database with new data. This is put on my activity's onCreate method: shiftsViewModel = ViewModelProviders.of(this).get(ShiftsViewModel.class); shiftsViewModel .getShifts() .observe(this, this::populateAdapter); This is the populateAdapter method: private void populateAdapter(@NonNull final List<Shift> shifts){ recyclerView.setAdapter(new

Viewbinding with error: incompatible with attribute android:visibility

折月煮酒 提交于 2019-12-25 03:26:34
问题 I'm trying to set the visibility and the src of an ImageView using data binding. I don't know why this error is showing up, and I truely believe that this was working at one point, but I could be wrong. Layout: <data> <import type="android.view.View" /> <import type="android.support.v4.content.ContextCompat" /> <variable name="viewData" type="com.myapp.SomethingViewData" /> </data> ... <ImageView ... android:src="@{ContextCompat.getDrawable(context, viewData.getIconResource())}" android

Android JetPack Navigation : How to open a fragment from an activity not associated with it?

岁酱吖の 提交于 2019-12-25 01:06:46
问题 scenario : MainActivity.kt : activity_main.xml contains my_nav_host_fragment in mobile_navigation.xml first_frag_dest is the startDestination and there is second_frag_dest also, with respective classes FirstFragment.kt and SecondFragment.kt . I have setup bottom navigation for switch between two fragments using the Android Jetpack Navigation components. When the Second Fragment is opened for the first time if FirbaseUser is null, A Welcome Activity is launched which is configured for

Sync device contact list with Firebase using MVVM (Android Architecture Components)

橙三吉。 提交于 2019-12-24 21:26:47
问题 I've always used the structure below to identify whether a user has an account in my app. All of this code is placed in MainActivity , but Google Architecture Components suggests to separate UI from the back-end logic. I've followed the example below for integrating the contact list with MVVM structure. https://github.com/NaarGes/Android-Contact-List But I don't know how to insert the Firebase Realtime Database validation. private void getContactList(){ Cursor phones = getContext()

android paging library - which DataSource I should use

两盒软妹~` 提交于 2019-12-24 08:34:04
问题 What I Want: I want to implement Android Paging Library with network call only. What I Understood: So, DataSource has three classes that I can extend. PageKeyedDataSource: If your web service has pageNumber in url then you can use it. ItemKeyedDataSource: When you are fetching nested data then you can use it. For example getting replies on particular comment. PositionalDataSource: You can use when you know exact number of data is going to load. What I Tried : Code is below. MainActivity.java

Android Architecture Components LiveData

大城市里の小女人 提交于 2019-12-24 06:08:46
问题 I'm trying to implement a simple App using Architecture Components. I can get the info from RestApi services using Retrofit2. I can show the info in the respective Recyclerview and when I rotate the phone everything works as it should. Now I want to filter by a new kind of object (by string) Can someone guide me a little with the ViewModel, I don't know what is the best practice to do that... I'm using MVVM... This is my ViewModel: public class ListItemViewModel extends ViewModel { private