问题标签 [android-room]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
11331 浏览

android - Android 全文搜索

Android 是否提供了一种进行全文搜索的方法?

我知道什至不可能通过注释字段搜索联系人,因为谷歌是搜索公司,但如果没有 API,我会感到失望。

0 投票
1 回答
8015 浏览

android - 如何以编程方式清除 Android 中的 DataStore Preference 和 Room 数据

我正在开发一个 Android 应用程序。当我按下按钮时,我需要以编程方式清除数据,包括数据存储首选项和房间数据。

0 投票
13 回答
49284 浏览

android - How to import Room Persistence Library to an Android project

I recently saw the new feature announced on Google I/O Room Persistence Library to work with Sqlite databases on Android. I have been looking to the official documentation and I don't find which dependencies I should import to my gradle file on my Android project. Someone can give me a hand?

0 投票
6 回答
26792 浏览

database - Android Room Persistence 库和 Kotlin

我正在尝试使用 Kotlin 和Room Persistence Library编写一个简单的应用程序。我按照Android Persistence codelab 中的教程进行操作。

这是我AppDatabase在 Kotlin 中的课程:

但是当我尝试运行该应用程序时,它会立即崩溃。这是崩溃日志:

看起来这个类AppDatabase_Impl不是自动生成的。我检查了从 codelab 下载的原始 java 应用程序,发现它AppDatabase_Impl是自动生成的。

Kotlin 版本:1.1.2-3
房间版本:1.0.0-alpha1

有没有人有这方面的经验?

编辑: 使用kapt解决了我的问题。就我而言,我必须替换annotationProcessorkapt.

0 投票
2 回答
27105 浏览

android - Android Room:如何建模关系?

我刚刚开始使用 Room,虽然一切似乎都非常直观,但我目前并不真正了解我该如何处理人际关系。

因为 SQLite 是关系型数据库,所以可以指定对象之间的关系。尽管大多数 ORM 库允许实体对象相互引用,但 Room 明确禁止这样做。即使您不能使用直接关系,Room 仍然允许您定义实体之间的外键约束。(来源:https ://developer.android.com/topic/libraries/architecture/room.html#no-object-references )

  1. 您应该如何建模多对多一对多关系?
  2. 这在实践中会是什么样子(例如 DAO + 实体)?
0 投票
2 回答
6444 浏览

android - 如何将现有的 SQLite 应用程序迁移到 Room Persistance Library?

问这个问题可能有点早,但是否有可能以及如何将现有的 SQLite 数据库应用程序迁移/升级到新的 Android Room Persistance Library?

0 投票
1 回答
2021 浏览

android - Android Room ORM: Support custom build of SQLite

I need to use a custom build of SQLite (based on sqlite.org version https://sqlite.org/android/doc/trunk/www/index.wiki) so that I can use custom FTS Tokenizers and to use SEE to encrypt my databases.

I'm using the following code to create a Room database:

I tried to implement my own "SupportSQLiteOpenHelper.Factory" (SqliteOrgSQLiteOpenHelperFactory) and tried to implement all of the needed classes, but there are too many direct dependencies to "android.database." and "android.database.sqlite.". All of these dependencies seem to need to be wrapped in "SupportXXX" classes

Example: SupportSQLiteOpenHelper.Configuration depends on:

  • android.database.DatabaseErrorHandler
  • android.database.DefaultDatabaseErrorHandler
  • android.database.sqlite.SQLiteDatabase.CursorFactory

SupportSQLiteDatabase depends on:

  • android.database.sqlite.SQLiteTransactionListener
  • android.database.sqlite.SQLiteDatabase.CursorFactory

Am I missing something? Am I approaching this all wrong?

0 投票
2 回答
210 浏览

android - Room 的 JavaDocs 在哪里?

Room 听起来很有趣,但我在Android 开发者网站的 JavaDocs中找不到任何类,因为它们在搜索时没有出现。JavaDocs 是否可用于 Room?

0 投票
9 回答
161143 浏览

android - 如何将主键作为 Room Persistence lib 的自动增量

我正在创建一个实体(房间持久性库)类 Food,我想在其中创建foodId自动增量。

如何设置foodId自动增量字段?

0 投票
3 回答
2524 浏览

android - 房间持久性库查询 COLLATE LOCALIZED 不起作用

我正在使用今年 Google I/O 发布的新房间持久性库,到目前为止它运行良好,但不知何故,无法使用UNICODELOCALIZED对结果进行排序。唯一有效的是NOCASE,这在我的情况下是无用的。

有没有办法实现这个功能呢?

如果我像上面那样构建查询,我会收到一个错误: