android-architecture-components

How to create BottomSheetDialogFragment using Navigation Architecture Component?

六月ゝ 毕业季﹏ 提交于 2019-12-23 07:22:16
问题 I am using BottomSheetDialogFragment for displaying few custom setting's. Requirement: When i click on any tab in BottomSheetDialogFragment i replace the fragment and add it to backstack so that when user click's onBackPress or Up action it should go back the the last setting's fragment of BottomSheetDialogFragment. I want to use Navigation Architecture Component to simplify my transaction's. Issue: if i use Navigation Architecture Component to navigate from FragmentA to

How to create BottomSheetDialogFragment using Navigation Architecture Component?

故事扮演 提交于 2019-12-23 07:21:33
问题 I am using BottomSheetDialogFragment for displaying few custom setting's. Requirement: When i click on any tab in BottomSheetDialogFragment i replace the fragment and add it to backstack so that when user click's onBackPress or Up action it should go back the the last setting's fragment of BottomSheetDialogFragment. I want to use Navigation Architecture Component to simplify my transaction's. Issue: if i use Navigation Architecture Component to navigate from FragmentA to

Accessing strings.xml from ViewModel

心已入冬 提交于 2019-12-22 10:41:32
问题 I am using Dagger 2 DataBindng and the new Android Lifecycle components, which have ViewModels . Inside my ViewModel how could I get access to my strings.xml? I was thinking at first, to inject a Context into the viewModel , however, this will just leak memory. Are there any other ways? 回答1: There is an AndroidViewModel, which receives Application instance as parameter. From docs: Application context aware ViewModel . Subclasses must have a constructor which accepts Application as the only

Android Architecture Components: ViewModel/Repository vs bind to Service/IntentService

北战南征 提交于 2019-12-22 06:41:05
问题 I want to implement/refactor an app to the Android Architecture Components concept, see https://developer.android.com/jetpack/docs/guide In this topic Android Architecture Components ViewModel - communication with Service/IntentService, I found a very good answer to the architectural issue, see https://stackoverflow.com/a/46736146/6251815 But i want to ask, how to bind the service from a repository, because we have neither context nor activity here. To be clear on that, the question is about

Room user configurable order by queries

╄→尐↘猪︶ㄣ 提交于 2019-12-22 04:31:25
问题 I am migrating an app to use Room from normal Sqlite and one part that I am having trouble with is that there are several queries that have an order by statement that are user configurable, meaning they can change how they want to view the list order. What it seems is the Room does not allow for dynamic order by statements so I would have to make individual queries specific for each order by statement. Has anyone found a better way around this issue so I can have 1 query statement where the

Paging Library without Room

旧巷老猫 提交于 2019-12-22 04:00:57
问题 All examples of the new paging library have been with Room library and Room creates a Data Source for us. In my own case, I need to create my custom data source. Here is a method in my view model class that ought to return the live data. My livedata always returns null. LiveData<PagedList<ApiResult>> getData(){ LivePagedListProvider<Integer,ApiResult> p = new LivePagedListProvider<Integer, ApiResult>() { @Override protected DataSource<Integer, ApiResult> createDataSource() { return new

Xamarin.Android Architecture Components: Not getting callbacks for lifecycle events

我的未来我决定 提交于 2019-12-22 03:53:08
问题 I'm trying to use the architecture components package for detecting when the application enters background or foreground state. The problem is that the callbacks are not being invoked. In the sample code below, the methods onApplicationForegrounded and onApplicationBackgrounded are not invoked: namespace POC.Droid { [Application] public class MyApp : Application, ILifecycleObserver { static readonly string TAG = "MyApp"; public MyApp(IntPtr handle, Android.Runtime.JniHandleOwnership ownerShip

Android Room @Embedded annotation compilation fails for @NonNull annotated constructor parameters of a POJO defined in a library module

人盡茶涼 提交于 2019-12-22 03:43:44
问题 I have a POJO which I am embedding in a Room Entity; Please note that the POJO is defined in a library module ; @Entity public class Person { @PrimaryKey @NonNull private String uuid; @Embedded @NonNull private Address address; public Person(@NonNull String uuid, @NonNull Address address) { this.uuid = uuid; this.address = address; } @NonNull public String getUuid() { return uuid; } @NonNull public Address getAddress() { return address; } } public class Address { @NonNull private String

Recycler view not scrolling to the top after adding new item at the top, as changes to the list adapter has not yet occurred

六月ゝ 毕业季﹏ 提交于 2019-12-21 23:18:53
问题 I am getting the new list with new item at the start in my live data and then using its data to update the adapter viewModel.myLiveData.observe { this, Observer { myList -> adapter.submitList(myList) recyclerView.scrollToPosition(0) } 回答1: submitList does its work on a background thread, so there will always be race conditions that delays can't solve. Fortunately, we can use a RecyclerView.AdapterDataObserver callback to be informed when the list calculations are complete:

java.lang.IllegalStateException: Migration didn't properly handle table

爷,独闯天下 提交于 2019-12-21 21:20:59
问题 How do you migrate an empty field type to text in Room ? Right now I'm facing this issue : java.lang.IllegalStateException: Migration didn't properly handle data_table Expected: TableInfo{name='data_table', columns= url=Column{name='url', type='TEXT' , notNull=false, primaryKeyPosition=0}..... Found: TableInfo{name='data_table', columns= url=Column{name='url', type='' , notNull=false, primaryKeyPosition=0}..... I've tried using the UNDEFINED typeAffinity, but that has no effect. 回答1: The