android-mvvm

Unable to get provider androidx.lifecycle.ProcessLifecycleOwnerInitializr

99封情书 提交于 2020-07-20 07:21:28
问题 Getting error while running app which have dependencies 'androidx.lifecycle:lifecycle-extensions:2.1.0-alpha03' and 'androidx.lifecycle:lifecycle-viewmodel:2.1.0-alpha03' on device with Android 4.4. Works fine in device with Android 6 App getting crashed with error java.lang.RuntimeException: Unable to get provider androidx.lifecycle.ProcessLifecycleOwnerInitializer: java.lang.ClassNotFoundException: Didn't find class "androidx.lifecycle.ProcessLifecycleOwnerInitializer" on path: DexPathList[

Is it a good practice to observeForever in Repository class? db+network paged list

泪湿孤枕 提交于 2020-06-26 03:23:31
问题 Im building an app following architecture guidelines.Implemented room db caching + network.Need to get latest page number from separate entity. My model: @Entity(tableName = "top_rated_movie_page") public class Top_Rated_Movies_Page { @PrimaryKey(autoGenerate = true) private int db_id; private Integer page; private Integer total_results; private Integer total_pages; @Ignore private List<Result> results; ... Result class contains data which i display in my paged list which observes changes

Updating a single item in a recylerview. I am using paging library and would like to update a single item/row

馋奶兔 提交于 2020-06-25 06:49:30
问题 I am passing pagedlist values to adapter using submit list. when i update a single item consider i am clicking a like button of a feed in a recyclerview. how to update the single item. i am following this example for paging implementation https://github.com/saquib3705/PagingLibrarySampleApp which just loads data and update the recyclerview. I would like to add like button for the items and update the list when user liked how to achieve it. Also look at this which is what i m exactly looking

Koin sharedViewModel with SavedStateHandle

余生颓废 提交于 2020-06-16 01:30:32
问题 I have single activity application and number of fragments. Some of these fragments are using my viewmodel, typically like this: private val myViewModel: MyViewModel by sharedViewModel() What if I want to have the model both shared and keep its state with SavedStateHandle? I cannot figure out if this is supported and if so, how it needs to be used (declaring viewmodel as stateViewModel in hosting activity is not working). 回答1: Update: as koin 2.1.6 is around, they introduced org.koin.androidx

How to check permission is granted in ViewModel?

旧巷老猫 提交于 2020-06-11 02:37:06
问题 I need to ask permission for contacts and when application starts I'm asking,in ViewModel part I need to call method which requires permission. I need to check permission is granted by user or not and then call, but for checking permission I need to have access Activity. while in my ViewModel I don't have a reference to Activity and don't want to have, How I can overcome, the problem? 回答1: I just ran into this problem, and I decided to use make use of LiveData instead. Core concept: ViewModel

Use the same instance of view model in multiple fragments using dagger2

痴心易碎 提交于 2020-06-01 05:36:25
问题 I am using only dagger2 ( not dagger-android ) in my project. It's working fine to inject the ViewModel using multibinding. But there's one problem with that previously without dagger2 I was using the same instance of viewmodel used in activity in multiple fragments (using fragment-ktx method activityViewModels()), but now since dagger2 is injecting the view model it's always gives the new instance (checked with hashCode in each fragment) of the viewmodel for each fragment, that's just breaks

LiveData Paged List size is always 0

偶尔善良 提交于 2020-05-27 06:16:05
问题 I implemented Paging using android paging library. The ViewModel returns a LiveData<PagedList<MyObject>> and I observe that in the fragment where I set the adapter and everything is working good, except that when I want to check the size of the list is always 0. viewModel.getSearchResults().observe(this, mList -> { adapter.submitList(mList); Log.e("Count", String.valueOf(mList.size())); }); Where mList is a PagedList<MyObject> 回答1: If you look at Loading Data from PagedList documentation you

LiveData Paged List size is always 0

…衆ロ難τιáo~ 提交于 2020-05-27 06:15:59
问题 I implemented Paging using android paging library. The ViewModel returns a LiveData<PagedList<MyObject>> and I observe that in the fragment where I set the adapter and everything is working good, except that when I want to check the size of the list is always 0. viewModel.getSearchResults().observe(this, mList -> { adapter.submitList(mList); Log.e("Count", String.valueOf(mList.size())); }); Where mList is a PagedList<MyObject> 回答1: If you look at Loading Data from PagedList documentation you

LiveData Paged List size is always 0

梦想的初衷 提交于 2020-05-27 06:15:10
问题 I implemented Paging using android paging library. The ViewModel returns a LiveData<PagedList<MyObject>> and I observe that in the fragment where I set the adapter and everything is working good, except that when I want to check the size of the list is always 0. viewModel.getSearchResults().observe(this, mList -> { adapter.submitList(mList); Log.e("Count", String.valueOf(mList.size())); }); Where mList is a PagedList<MyObject> 回答1: If you look at Loading Data from PagedList documentation you