android-livedata

RefreshShows() in Repository get called every time onCreate() callback of Activity get called

瘦欲@ 提交于 2020-06-01 06:24:06
问题 I have following project in Github : https://github.com/Ali-Rezaei/TVMaze I have started to using Koin as dependency injection framework in a sample app : class TVMazeApplication : Application() { override fun onCreate() { super.onCreate() startKoin { androidContext(this@TVMazeApplication) modules(networkModule) modules(persistenceModule) modules(repositoryModule) modules(viewModelModule) } } } This is my repository class : class ShowRepository( private val dao: ShowDao, private val api:

Room LiveData fires twice with one stale emission

蹲街弑〆低调 提交于 2020-05-29 10:28:49
问题 This issue was originally observed in a project with MVVM architecture (single activity / multiple fragments) when performing an insert/delete operation to the database and then navigating back to the home fragment. The home fragment then resubscribes to the LiveData in the home ViewModel and LiveData emits twice: One incorrect stale event corresponding to before the database operation A second correct event corresponding to after the database operation I have created a very simple example

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

how to change LiveData observable query parameter with room database in android?

给你一囗甜甜゛ 提交于 2020-05-27 05:41:28
问题 I am using live data with room database and my activity observes live data provided from room database. @Query("SELECT * FROM BUS WHERE BUS_CATEGORY = :busCategory") LiveData<List<Bus>> getLiveBuses( String busCategory); ViewModels gets LiveData via Dao(Data Access Object) and activity observes this live data. Now it works fine. But when busCategory changes i can't modify this live data to get buses for newly selected busCategory. So how can i observe this same liveData where query parameters

Android live data - observe always fires after config change

拥有回忆 提交于 2020-05-25 15:28:44
问题 I'm currently refactoring my code to include ViewModel with LiveData provided by android.arch library. I have a simple activity that sends request for a password change to server and acts according to HTTP response code. For that purpose I have created class that extends ViewModel for data and a repository class to call server. My ViewModel class has one MutableLiveData field which I'm subscribing to from my activity using .observe(...) method. The issue is that code inside .observe(...)

Android live data - observe always fires after config change

怎甘沉沦 提交于 2020-05-25 15:26:51
问题 I'm currently refactoring my code to include ViewModel with LiveData provided by android.arch library. I have a simple activity that sends request for a password change to server and acts according to HTTP response code. For that purpose I have created class that extends ViewModel for data and a repository class to call server. My ViewModel class has one MutableLiveData field which I'm subscribing to from my activity using .observe(...) method. The issue is that code inside .observe(...)

Some fragment observers trigger after pop from back stack although data is not changed

让人想犯罪 __ 提交于 2020-05-21 07:25:47
问题 I have some problem in nested fragment in Kotlin. I have nested fragment with ViewModel. After resuming fragment from back button press all observers on viewModel LiveData triggers again although my data does not changed. First i googled and tried for define observer in filed variable and check if it is initialized then do not observer it again: lateinit var observer: Observer fun method(){ if (::observer.isInitialized) return observer = Observer{ ... } viewModel.x_live_data.observe

Some fragment observers trigger after pop from back stack although data is not changed

谁说我不能喝 提交于 2020-05-21 07:25:08
问题 I have some problem in nested fragment in Kotlin. I have nested fragment with ViewModel. After resuming fragment from back button press all observers on viewModel LiveData triggers again although my data does not changed. First i googled and tried for define observer in filed variable and check if it is initialized then do not observer it again: lateinit var observer: Observer fun method(){ if (::observer.isInitialized) return observer = Observer{ ... } viewModel.x_live_data.observe