android-room

How to get a specific Entity in Room

半腔热情 提交于 2020-01-06 06:31:48
问题 So, I'm using Room database to store courses and I'm stuck on the method that returns the course with the name(course) that I want because it's always returning null. I have diminished my database to have 2 courses with the course variable as: As you can see in the picture above, when I try to get the CourseEnt in the Repository with course = fun , which I can see below that it exists, it returns a LiveData with a null value instead of the CourseEnt that I wanted. Any idea on what I'm doing

Android Room recursive relation

狂风中的少年 提交于 2020-01-06 05:59:20
问题 It's possible for room to have Recursive relations? I have an Entity that can be nested in a Parent/Childs structures something like this Category1 |_________Category2 |_________Category3 | |_________Category4 |_________Category5` I'm copying this structure from a json that is obtained from a WebService. This is my current Entity: @Entity(tableName = "categories") public class Category { @PrimaryKey @NonNull private String code; private String name; private String parentCode; @Relation

Android: update single Room column with Dao call from repository?

隐身守侯 提交于 2020-01-06 05:51:10
问题 I have a Room database and RecyclerView that shows a list of CardViews. One of the database columns holds Sort Index values so the CardViews can easily be sorted and moved within the RecyclerView list. I have a Dao call to update the Sort Index values whenever a CardView is moved, deleted or added. Room requires CRUD on a background thread and the syntax I have in the AsyncTask() in the respository that calls the Dao method is wrong. I am trying to pass the individual "int" sortOrders and the

How to use paging library with Room Dao without using any View classes

流过昼夜 提交于 2020-01-06 03:57:09
问题 I have an android service (no UI) with a class FooManager that needs to fetch all Foo objects (rows) in a database table foo using room and the androidx paging library. All examples I have found show how to do this using the PagedListAdapter and RecyclerView. Since I have no UI I cannot use view classes. Here is what I have tried: In my FooDao class I have the following method: @Query("SELECT * FROM foo") DataSource.Factory<Integer, Foo> getAllPaged(); In the constructor for my FooManager

Should I change all annotationProcessor to kapt in Kotlin project

浪子不回头ぞ 提交于 2020-01-05 06:36:07
问题 I noticed that I have to use kapt instead of annotationProcessor to make Dagger 2 work properly in my Kotlin project. Do I have to do the same to all the libraries (specifically Glide and Room )? 回答1: Yes, it is recommended to do so. The documentation stated: If you previously used the Android support for annotation processors, replace usages of the annotationProcessor configuration with kapt . If your project contains Java classes, kapt will also take care of them. Read more on Using kapt 来源

Should I change all annotationProcessor to kapt in Kotlin project

不羁的心 提交于 2020-01-05 06:35:33
问题 I noticed that I have to use kapt instead of annotationProcessor to make Dagger 2 work properly in my Kotlin project. Do I have to do the same to all the libraries (specifically Glide and Room )? 回答1: Yes, it is recommended to do so. The documentation stated: If you previously used the Android support for annotation processors, replace usages of the annotationProcessor configuration with kapt . If your project contains Java classes, kapt will also take care of them. Read more on Using kapt 来源

Filling an adapter from different LiveData sources

断了今生、忘了曾经 提交于 2020-01-04 06:25:30
问题 I'm playing with LiveData and want to understand what it can do. I want to fill my RecyclerView with data from different sources by switch(using filters if you like). Filtering values inside an adapter is not an option. So, I decided to use MediatorLiveData inside my view model. Dao: @Query("SELECT * FROM tasks WHERE completed = 0") LiveData<List<Task>> getActiveTasksLiveData(); @Query("SELECT * FROM tasks") LiveData<List<Task>> getAllTasksLiveData(); @Query("SELECT * FROM tasks WHERE

how to get Deffered from DAO?

ⅰ亾dé卋堺 提交于 2020-01-04 05:55:29
问题 I want to get Kotlin Coroutnies Deffered from DAO @Query("select * from gameprocess where cabinId = :cabinId ") fun getAllGameProccesBiCabin(cabinId :Int) : Deferred<GameProcess> but it does not compile (room does not know how to handle Deffered), but I need to use 'wait' from 'Deffered' how can do this? as another option I could use extension function from this post but, dont know how to integrate it into dao: https://codelabs.developers.google.com/codelabs/kotlin-coroutines/index.html?index

how to get Deffered from DAO?

故事扮演 提交于 2020-01-04 05:55:09
问题 I want to get Kotlin Coroutnies Deffered from DAO @Query("select * from gameprocess where cabinId = :cabinId ") fun getAllGameProccesBiCabin(cabinId :Int) : Deferred<GameProcess> but it does not compile (room does not know how to handle Deffered), but I need to use 'wait' from 'Deffered' how can do this? as another option I could use extension function from this post but, dont know how to integrate it into dao: https://codelabs.developers.google.com/codelabs/kotlin-coroutines/index.html?index

Room Migration Alter Table not adding new column & migrate getting called again and again

故事扮演 提交于 2020-01-03 18:46:20
问题 So basically i am using room and trying to add migration from database version 1 to 2 but my alter command is not working My current implementation is below : void init() { db = Room.databaseBuilder(Global.getInstance(), AppDatabase.class, "feed").addMigrations(MIGRATION_1_2).build(); } Migration property : static final Migration MIGRATION_1_2 = new Migration(1,2) { @Override public void migrate(SupportSQLiteDatabase database) { database.execSQL("ALTER TABLE 'post' ADD COLUMN 'age' INTEGER