android-room

Room - LiveData not triggered

▼魔方 西西 提交于 2021-02-08 10:05:42
问题 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

How to insert null field using Room Android

China☆狼群 提交于 2021-02-08 05:14:06
问题 I'm trying to play around and understand the Room persistence library of Android. So far I got how to insert things and query them, but now I'm trying to have 2 constructors in order to not insert a field if I dont want to. Something like this: public ImageData(int id, String name, String title, String description, int locationId) { ..... public ImageData(int id, String name, String title, String description) { In some cases I won't have a location and therefore I don't want to insert

How to insert null field using Room Android

亡梦爱人 提交于 2021-02-08 05:11:58
问题 I'm trying to play around and understand the Room persistence library of Android. So far I got how to insert things and query them, but now I'm trying to have 2 constructors in order to not insert a field if I dont want to. Something like this: public ImageData(int id, String name, String title, String description, int locationId) { ..... public ImageData(int id, String name, String title, String description) { In some cases I won't have a location and therefore I don't want to insert

Can I use Room Persistence for a different type of Database?

好久不见. 提交于 2021-02-08 02:01:37
问题 I know that room is an abstraction layer over SQLite, I just want to know if I can use it for a different type of Database. I want to use Room to a special version of SQLite with geospatial support, is it possible? I really can't find an answer about this one. Android Spatialite Thanks in advance! 回答1: Yes, if you are willing to write the bridge code for it. One of the methods that you can call on a RoomDatabase.Builder is openHelperFactory(). This takes an instance of SupportSQLiteOpenHelper

Can I use Room Persistence for a different type of Database?

ぃ、小莉子 提交于 2021-02-08 02:01:26
问题 I know that room is an abstraction layer over SQLite, I just want to know if I can use it for a different type of Database. I want to use Room to a special version of SQLite with geospatial support, is it possible? I really can't find an answer about this one. Android Spatialite Thanks in advance! 回答1: Yes, if you are willing to write the bridge code for it. One of the methods that you can call on a RoomDatabase.Builder is openHelperFactory(). This takes an instance of SupportSQLiteOpenHelper

R8 minify: Type defined multiple times

孤街浪徒 提交于 2021-02-07 09:11:01
问题 When building a signed release APK I'm getting following error: .gradle/caches/transforms-2/files-2.1/532a317ccd54c8ae4f622faeb8b534a9/jetified-wordup-core-0.2.1-runtime.jar:de/codereddev/wordup/database/WordDao_Impl$5.class, Type de.codereddev.wordup.database.WordDao_Impl$5 is defined multiple times: /home/codered_dev/.gradle/caches/transforms-2/files-2.1/532a317ccd54c8ae4f622faeb8b534a9/jetified-wordup-core-0.2.1-runtime.jar:de/codereddev/wordup/database/WordDao_Impl$5.class, /home/codered

RxJava2 toList() never emits

心已入冬 提交于 2021-02-07 07:53:41
问题 So I have following Disposable which doesn't work. I am using Room to get all rows from a table as a list, map each of them to something and create a list and then it doesn't continue from there. storedSuggestionDao .getSuggestionsOrderByType() //Flowable .doOnNext(storedSuggestions -> Timber.e("storedSuggestions: " + storedSuggestions)) //this work .flatMapIterable(storedSuggestions -> storedSuggestions) .map(Selection::create) )) .doOnNext(selection -> Timber.e("Selection: " + selection)) /

Room DAO Order By ASC or DESC variable

帅比萌擦擦* 提交于 2021-02-07 04:54:40
问题 I'm trying to make a @Query function in my @Dao interface which has a boolean parameter, isAsc to determine the order: @Query("SELECT * FROM Persons ORDER BY first_name (:isAsc ? ASC : DESC)") List<Person> getPersonsAlphabetically(boolean isAsc); Apparently this isn't allowed. Is there a work around here? EDIT: It seemed odd to use two queries (below) since the only difference is ASC and DESC : @Query("SELECT * FROM Persons ORDER BY last_name ASC") List<Person> getPersonsSortByAscLastName();

How to avoid occurring many AsyncTask class in my Android Room repository?

我的未来我决定 提交于 2021-02-07 04:19:21
问题 I'm learning how to use Android Room from google-developer-training, where I found example of repository class . I try to simplify my SportRepository class. I wonder how to avoid repetition of inner class ...AsyncTask in my code. Here is very sample example: @Singleton class SportRepository { val LOG_TAG = SportRepository::class.java.name @Inject lateinit var sportDAO: SportDAO var list: LiveData<List<Sport>> init { App.app().appComponent()?.inject(this) list = sportDAO.getAll() } fun insert

How to filter in one to many relationship with android room db

好久不见. 提交于 2021-02-04 21:40:57
问题 I have a User Entity and a Record entity. I want to get a list that shows all users and their record list filtered by record's date. However, I got stuck with not being able to filter the result with conditions. def room_version = "2.2.5" implementation "androidx.room:room-runtime:$room_version" @Entity(tableName = "user_table") public class User { @PrimaryKey public long id; public String name; } @Entity(tableName = "record_table") public class Record { @PrimaryKey @ColumnInfo(name = "record