英文:
How to drop a Room database?
问题
你如何删除我的应用程序的Room数据库?我找到了clearAllTables()
方法,但这不是我想要的。相反,我真的想在用户注销时删除数据库并重新开始。
英文:
How can I delete the Room database of my app? I've found the clearAllTables()
method, but that's not what I want. Instead I really want to delete the database on user logout and start all over.
答案1
得分: 4
Step #1: 调用 close()
关闭你的 RoomDatabase
。这将合并 wal
和 shm
文件的内容到主 SQLite 数据库文件中,只留下一个文件需要删除。
Step #2: 删除该数据库文件。如果你将其存储在默认位置,你可以调用 Context
上的 deleteDatabase()
。
英文:
Step #1: Call close()
on your RoomDatabase
. That should coalesce the contents of the wal
and shm
files into the main SQLite database file, leaving you only one file to delete.
Step #2: Delete that database file. If you stored it in the default location, you can call deleteDatabase()
on a Context
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论