android-room

Parcelable Model reinstatiates, MVVM Room LiveData

落花浮王杯 提交于 2021-02-11 14:01:17
问题 Here is my problem, I am using mvvm to load profile data from Dao, which was earlier updated when user logs in. Or if a new user an empty model loads. see my BasicProfileFragment and ViewModel. I am using LiveData to update fragment from Dao initially. Next, I want to edit/update the fields in different ways. keyboard input and updating data by Navigating to other fragments. Where data loaded as list from server. For eg. clicking the Gender strip and Navigate to Gender Fragment, Data

When / How to Create / Destroy Room Database

微笑、不失礼 提交于 2021-02-11 13:38:39
问题 I was wondering if someone could either point me to documentation to / clarify when to create or destroy a room database instance. Also how you would effectively open / close it ? If I have a RoomDatabase object that gets injected via dagger to a presenter is that cool and then I just access various Daos? I'm worried about having the object lingering and taking up memory. 回答1: Instead of Injecting the RoomDatabase into your presenter you could Inject a DataManager Singleton class. This

Android Room: apply multiple columns in relation of embedded object

烈酒焚心 提交于 2021-02-10 18:16:14
问题 In my Android App I am using Room for data storage. I am currently facing the problem, that I need to put 2 columns in my @Relation of the embedded object because the relation depends on 2 columns. See below the structure: @Entity(tableName = "damages") public class Damage { @PrimaryKey(autoGenerate = true) @NonNull private Long id; @NonNull private Long projectId; @NonNull private Long codeId; private String description; ... } @Entity(tableName = "damage_codes") public class DamageCode {

Android Room: apply multiple columns in relation of embedded object

爷,独闯天下 提交于 2021-02-10 18:14:08
问题 In my Android App I am using Room for data storage. I am currently facing the problem, that I need to put 2 columns in my @Relation of the embedded object because the relation depends on 2 columns. See below the structure: @Entity(tableName = "damages") public class Damage { @PrimaryKey(autoGenerate = true) @NonNull private Long id; @NonNull private Long projectId; @NonNull private Long codeId; private String description; ... } @Entity(tableName = "damage_codes") public class DamageCode {

How to search two tables sharing a foreign key (I think I'm asking this right…)?

旧城冷巷雨未停 提交于 2021-02-10 14:21:06
问题 Dog entity @Entity(tableName = "dog_table") public class DogEntity { private int mId; private String mName, mBreed; etc.. } Toy entity @Entity(tableName = "toy_table") public class ToyEntity { private int mId; private String mName, mBrand; etc.. } DogAndToy join table entity @Entity(tableName = "dog_and_toy_join_table", primaryKeys = {"mDogID", "mToyId"}, foreignKeys = { @ForeignKey( entity = DogEntity.class, parentColumns = "mId", childColumns = "mDogID", onDelete = ForeignKey.CASCADE,

What is the best way to not use allowmainthreadqueries() using Android Room?

為{幸葍}努か 提交于 2021-02-10 14:14:50
问题 I always use allowmainthreadqueries() in Android Room. But many people say it is not recommend to do it. With this function, Room is very easy to use. But if i should change my app to not using this function, How do I do that? Is there an effective way to do it? 回答1: Yes, It is not a good approach to query DB on Main Thread. There are different ways, to keep the DB operation off the main(UI) thread, Mainly Kotlin Coroutines. https://developer.android.com/codelabs/kotlin-android-training

Observer not triggered on room database change

白昼怎懂夜的黑 提交于 2021-02-09 07:56:20
问题 I am trying to update a RecyclerView when a room database is changed. However the onChanged method of the observer defined in the MainActivity does not get called, when a change to the database occurs. If I let the DAO return LiveData instead of a List<> and use LiveData in my ViewModel it works as intended. However I need MutableLiveData as I want to change my query to the database during runtime. My setup: MainActivity.java BorrowedListViewModel viewModel = ViewModelProviders.of(this).get

Observer not triggered on room database change

泄露秘密 提交于 2021-02-09 07:55:43
问题 I am trying to update a RecyclerView when a room database is changed. However the onChanged method of the observer defined in the MainActivity does not get called, when a change to the database occurs. If I let the DAO return LiveData instead of a List<> and use LiveData in my ViewModel it works as intended. However I need MutableLiveData as I want to change my query to the database during runtime. My setup: MainActivity.java BorrowedListViewModel viewModel = ViewModelProviders.of(this).get

Observer not triggered on room database change

∥☆過路亽.° 提交于 2021-02-09 07:53:45
问题 I am trying to update a RecyclerView when a room database is changed. However the onChanged method of the observer defined in the MainActivity does not get called, when a change to the database occurs. If I let the DAO return LiveData instead of a List<> and use LiveData in my ViewModel it works as intended. However I need MutableLiveData as I want to change my query to the database during runtime. My setup: MainActivity.java BorrowedListViewModel viewModel = ViewModelProviders.of(this).get

Room - LiveData not triggered

喜夏-厌秋 提交于 2021-02-08 10:07:52
问题 I'm trying to work with Room database & LiveData. I have ViewModels which holds LiveData they got from dao. If I update a Transaction , then LiveData<List<Transaction>> is observed ok, but LiveData<Transaction> is not observed at all. How is that possible? What am i doing wrong? public abstract class Dao { @Query("SELECT * FROM transact WHERE deleted = :value") public abstract LiveData<List<Transaction>> allTransactions(boolean value); @Query("SELECT * FROM transact WHERE guid = :guid AND