如何删除一个Room数据库?

huangapple go评论57阅读模式
英文:

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。这将合并 walshm 文件的内容到主 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.

huangapple
  • 本文由 发表于 2023年5月20日 23:52:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76296079.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定