如何以编程方式从 Android 中删除 SQLite 数据库 [英] How to delete SQLite database from Android programmatically

查看:44
本文介绍了如何以编程方式从 Android 中删除 SQLite 数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式从 Android 文件系统 中删除数据库文件?我可以让一个 shell 脚本启动 adb 依次在 Android 空间中运行一个 shell 脚本来删除数据库吗?我可以在 JUnit 测试用例中完成这项工作吗(使用 system() 调用)?

I would like to delete the database file from the Android file system programatically? Can I have a shell script launch adb which in turns runs a shell script in the Android space to do the database deletion? Can I get this done from within a JUnit test case (with a system() call)?

如何在 Android 中删除整个数据库?我需要让整个事情消失,以便我可以测试数据库创建.我可以删除桌子,但这还不够.这是在模拟器中,而不是在手机上.

How do I delete an entire database in Android? I need to make the whole thing go away so I can test database creation. I can drop tables, but that's not enough. This is in the emulator, not on a phone.

推荐答案

一旦你有你的上下文并知道数据库的名称,使用:

Once you have your Context and know the name of the database, use:

context.deleteDatabase(DATABASE_NAME);

当这一行运行时,数据库应该被删除.

When this line gets run, the database should be deleted.

这篇关于如何以编程方式从 Android 中删除 SQLite 数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆