android-livedata

How to access room db using viewmodel, repository, and livedata

孤街浪徒 提交于 2020-08-26 09:46:12
问题 I am new to android development. In my app, I need to have a user table in the database. I have created the database using room. Now, if I allow to run the db in the main thread, my app is running fine. But, I don't want to run it in the main thread. So, I created the repository and viewmodel classes and calling the db in the main thread using the viewmodel. Still if I don't put allowMainThreadQueries() in the database building statement, java.lang.IllegalStateException: Cannot access

Observing SharedPreferences Data

孤者浪人 提交于 2020-08-24 01:19:25
问题 I am trying to observe data changes in shared preferences. I found this similar question answered by @SimplyProgrammerand followed the steps that he directed and at the end of the day my observer was still not working. Then I decided to seek some assistance to better understand why. this is my implementation I started by implementing the abstract live data SharedPreferences preference; String key; T defValue; public SharedPrefferenceLiveData(SharedPreferences preference,String key,T defValue)

Observing SharedPreferences Data

霸气de小男生 提交于 2020-08-24 01:17:11
问题 I am trying to observe data changes in shared preferences. I found this similar question answered by @SimplyProgrammerand followed the steps that he directed and at the end of the day my observer was still not working. Then I decided to seek some assistance to better understand why. this is my implementation I started by implementing the abstract live data SharedPreferences preference; String key; T defValue; public SharedPrefferenceLiveData(SharedPreferences preference,String key,T defValue)

how do i remove row from recyclerview using room?

随声附和 提交于 2020-08-17 07:57:27
问题 The bounty expires in 3 days . Answers to this question are eligible for a +50 reputation bounty. Wini is looking for a canonical answer . I'm trying to delete an row of recyclerview using room.im doing swipe to delete a particular row.... here is my Address table--> @Entity(tableName = "address") class Address { @PrimaryKey(autoGenerate = true) var id = 0 @ColumnInfo(name = "address") var address: String? = null } AddressDao: @Dao interface AddressDao { @Insert suspend fun addData(address:

how do i remove row from recyclerview using room?

孤街浪徒 提交于 2020-08-17 07:56:48
问题 The bounty expires in 3 days . Answers to this question are eligible for a +50 reputation bounty. Wini is looking for a canonical answer . I'm trying to delete an row of recyclerview using room.im doing swipe to delete a particular row.... here is my Address table--> @Entity(tableName = "address") class Address { @PrimaryKey(autoGenerate = true) var id = 0 @ColumnInfo(name = "address") var address: String? = null } AddressDao: @Dao interface AddressDao { @Insert suspend fun addData(address:

android LiveData or coroutines channel

非 Y 不嫁゛ 提交于 2020-07-10 09:35:10
问题 Having app using LiveData with ViewModel for UI to observe the data update in the repository. It is working fine. Now someone brought it up the "LiveData has not been well adopted, maybe it should be switch to use coroutines' channel". First of all not sure the statement about LiveData is accurate or not. I am sure with coroutines' feature it could be done without LiveData. But I feel every one has its targeted task, and from the speech/sample of Google the LiveData is built with Android

android LiveData or coroutines channel

空扰寡人 提交于 2020-07-10 09:34:56
问题 Having app using LiveData with ViewModel for UI to observe the data update in the repository. It is working fine. Now someone brought it up the "LiveData has not been well adopted, maybe it should be switch to use coroutines' channel". First of all not sure the statement about LiveData is accurate or not. I am sure with coroutines' feature it could be done without LiveData. But I feel every one has its targeted task, and from the speech/sample of Google the LiveData is built with Android

JUnit5 test with LiveData doesn't execute subscriber's callback

Deadly 提交于 2020-07-06 17:48:34
问题 Background: I have a simple application that fetches movie list using rests API call. The project structure is given below, Activity -> ViewModel -> Repository -> ApiService (Retrofit Interface) The activity subscribes to a LiveData and listens for events changes The ViewModel hosts the MediatorLiveData observed by the activity. Initially the ViewModel sets a Resource.loading(..) value in MediatorLiveData . The ViewModel then calls the repository to get the movie list from ApiService The

JUnit5 test with LiveData doesn't execute subscriber's callback

好久不见. 提交于 2020-07-06 17:44:37
问题 Background: I have a simple application that fetches movie list using rests API call. The project structure is given below, Activity -> ViewModel -> Repository -> ApiService (Retrofit Interface) The activity subscribes to a LiveData and listens for events changes The ViewModel hosts the MediatorLiveData observed by the activity. Initially the ViewModel sets a Resource.loading(..) value in MediatorLiveData . The ViewModel then calls the repository to get the movie list from ApiService The