如何在android系统调用onUpgrade(),与SQLite数据库工作 [英] How to invoke onUpgrade() in android, for work with sqlite database

查看:467
本文介绍了如何在android系统调用onUpgrade(),与SQLite数据库工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面讲在Android中数据库操作(源码)的文章,并在出现问题至极,我不能找到解决办法就来了。

I'm following some articles about database manipulations (sqlite) in android, and came across a problem wich I can't find solution for.

基本上我想要数据库中每次运行的应用程序(测试)时间重新创建。

Essentially I want database to be recreated every time I run application (Testing purposes).

推荐答案

如果你想每次升级的数据库,你可以尝试调用 onUpgrade 在<$ C $ manuallly C>的onCreate 每次添加一个布尔变量来避免无限递归调用。 (这是调试code,所以你应该用// TODO注释或类似它提醒你的东西对它进行标记。)

If you want to upgrade the database everytime you could try to call onUpgrade manuallly in onCreate everytime and add a boolean variable to avoid infinite recursive calls. (it's debug code, so you should mark it with a // todo comment or something similar which alerts you.)

或者,创建一个名为方法 destroyDB 之后

Or, make a method called destroyDB and add it after

DatabaseHandler database = new DatabaseHandler(this);

这不我上面说的同样的事情(电话onUpgrade),但你避免了无穷递归调用,如果你不记得这不,当你看到 destroyDB 您将检查这个方法做了什么。

which does the same thing i said above (calls onUpgrade) but you avoid the infinity recursive calls and if you don't remember this when you see destroyDB you will check what this method does.

或更改版本手动每次你需要检查数据库。

Or change version manually everytime you need to check database.

这篇关于如何在android系统调用onUpgrade(),与SQLite数据库工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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