android-room

How can I change the default location of a Room database?

与世无争的帅哥 提交于 2020-01-13 09:32:46
问题 I want to change the location of the Android Room Database. I know that the database is inside of the files system, and I need to get root permissions, but I do not want to root my phone. The idea is change the database location to SD card, and can access it without root my phone 回答1: Just put the location path in the name of the database. I.e.: AppDatabase db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "database-name").build(); Put the router in database name. I.e.:

How can I change the default location of a Room database?

我的未来我决定 提交于 2020-01-13 09:31:51
问题 I want to change the location of the Android Room Database. I know that the database is inside of the files system, and I need to get root permissions, but I do not want to root my phone. The idea is change the database location to SD card, and can access it without root my phone 回答1: Just put the location path in the name of the database. I.e.: AppDatabase db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "database-name").build(); Put the router in database name. I.e.:

Convert LiveData to MutableLiveData

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-12 15:47:10
问题 Apparently, Room is not able to handle MutableLiveData and we have to stick to LiveData as it returns the following error: error: Not sure how to convert a Cursor to this method's return type I created a "custom" MutableLiveData in my DB helper this way: class ProfileRepository @Inject internal constructor(private val profileDao: ProfileDao): ProfileRepo{ override fun insertProfile(profile: Profile){ profileDao.insertProfile(profile) } val mutableLiveData by lazy { MutableProfileLiveData() }

Why Does Room Delete Operation(With RxJava) Gives UI Thread Error Even Specifying Different Subcribe Thread?

て烟熏妆下的殇ゞ 提交于 2020-01-11 03:08:29
问题 So simply, the DAO @Query("DELETE FROM Things WHERE someIdOfTheThing IN (:listOfId)") abstract fun deleteThings(listOfId: MutableList<String>): Maybe<Int> usage, mDisposables.add(mThingsDao .deleteThings(listOfId) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe({ ... }, { ... }) ) and error, // Cannot access database on the main thread since it may potentially lock the UI for a long period of time. The simple idea i was thinking is to specify subscribeOn

LiveData.getValue() returns null with Room

為{幸葍}努か 提交于 2020-01-09 07:14:19
问题 Java POJO Object public class Section { @ColumnInfo(name="section_id") public int mSectionId; @ColumnInfo(name="section_name") public String mSectionName; public int getSectionId() { return mSectionId; } public void setSectionId(int mSectionId) { this.mSectionId = mSectionId; } public String getSectionName() { return mSectionName; } public void setSectionName(String mSectionName) { this.mSectionName = mSectionName; } } My Query method @Query("SELECT * FROM section") LiveData<List<Section>>

LiveData.getValue() returns null with Room

橙三吉。 提交于 2020-01-09 07:13:10
问题 Java POJO Object public class Section { @ColumnInfo(name="section_id") public int mSectionId; @ColumnInfo(name="section_name") public String mSectionName; public int getSectionId() { return mSectionId; } public void setSectionId(int mSectionId) { this.mSectionId = mSectionId; } public String getSectionName() { return mSectionName; } public void setSectionName(String mSectionName) { this.mSectionName = mSectionName; } } My Query method @Query("SELECT * FROM section") LiveData<List<Section>>

Room database: getting SELECT MAX() twice after creating new RecyclerView item

你说的曾经没有我的故事 提交于 2020-01-06 08:10:57
问题 I have a RecyclerView list of CardView items that is working properly. Upon creation of a new CardView that is inserted into the database, I would like to fire a Toast that informs the user that the CardView was successfully added and show the CardView number. The CardView number is the Id of the CardView item inserted into the database. The data is saved to the database when the user clicks on a Save button that fires onClickSave(). I set up an @Query in the Dao to get the MAX(cardId): Dao .

Complex query in Room android

旧街凉风 提交于 2020-01-06 07:53:29
问题 I am trying to use Room in my application but I have a very complex query that makes a recursive and inner join between multiple tables here is my query, fun test(categoryId: Int): String { return "WITH CTE AS (SELECT id, parent_id, id AS CategoryID FROM categories WHERE parent_id= 0 UNION ALL SELECT t.id, t.parent_id, t.id|| ', ' || CategoryID AS CategoryID FROM categories t INNER JOIN CTE c ON t.parent_id = c.id) SELECT CTE.CategoryID FROM CTE where CTE.id= " + categoryId + " ORDER BY CTE

Complex query in Room android

巧了我就是萌 提交于 2020-01-06 07:52:12
问题 I am trying to use Room in my application but I have a very complex query that makes a recursive and inner join between multiple tables here is my query, fun test(categoryId: Int): String { return "WITH CTE AS (SELECT id, parent_id, id AS CategoryID FROM categories WHERE parent_id= 0 UNION ALL SELECT t.id, t.parent_id, t.id|| ', ' || CategoryID AS CategoryID FROM categories t INNER JOIN CTE c ON t.parent_id = c.id) SELECT CTE.CategoryID FROM CTE where CTE.id= " + categoryId + " ORDER BY CTE

SQLCipher and CWAC-SafeRoom doubling the size of my APK

烈酒焚心 提交于 2020-01-06 07:31:53
问题 The size of these libraries really increase the APK size. It’s almost 50% my App size, taking it to 16.3 MBs and when I analyze the APK, sqlcipher-lib alone is 48.9% of my apk size i.e 7.3MBs!!! Is there any workaround? Edit: Since this is a DB related issue and I believe it's good if the specified tags remain referenced for specificity during search by other developers. I think the answer below addresses it better in order to keep the conversation along specific topics 回答1: This section of