为什么在使用Android Room时没有创建数据库文件? [英] Why is there no database file created when using Android Room?
问题描述
我将Room Persistence Library用于我的Android应用程序,但是在创建后,无法在设备上找到带有表的.sql文件.
I use the Room Persistence Library for my Android app, but after it's creation I can not find .sql file with tables on my device.
当我通过SQLiteOpenHelper
创建数据库时,可以在设备上的 data 文件夹中看到所有表,但是当我通过Room创建数据库时,任何地方都没有文件.
When I create database through SQLiteOpenHelper
I can see all my tables in folder data on the device, but when I create database through Room there is no file anywhere.
我在哪里可以看到所有表格的内容?
Where can I see the content of all my tables?
创建数据库代码:
@Provides
@Singleton
PokuponDataBase providePokuponDataBase() {
return Room.inMemoryDatabaseBuilder(SuperDealApp.getInstance().getApplicationContext(), PokuponDataBase.class, "PokuponRoomDatabase").build();
}
推荐答案
我找到了导致数据库消失的原因.这是因为我创建不正确.我使用Room.InMemoryDatabaseBuilder()而不是简单的Room.databaseBuilder(),并且在重新加载每个应用程序之后,重新创建了我的数据库,并且inMemory数据库也未创建任何文件.
I found the cause of disappearing my database. It was because I create it incorrectly. I use Room.InMemoryDatabaseBuilder() instead of simple Room.databaseBuilder() and after each application reloading my db was recreated and also inMemory database does not create any files.
这篇关于为什么在使用Android Room时没有创建数据库文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!