相关疑难解决方法(0)

Android:onUpgrade不调用数据库升级

我正在开发应用程序的第二个版本。我正面临一个问题。

在我的应用程序中,数据库位于资产文件夹中。现在,我想从第二个版本中的assets文件夹更新数据库。

我尝试将代码升级为:

// Data Base Version.
private static final int DATABASE_VERSION = 2;
Run Code Online (Sandbox Code Playgroud)

我将版本从1更改为2。

//构造函数

public DataBaseHelperClass(Context myContext) {     
    super(myContext, DATABASE_NAME, null ,DATABASE_VERSION);
    this.context = myContext;
    //The Android's default system path of your application database.
    DB_PATH = "/data/data/com.example.myapp/databases/";
}
Run Code Online (Sandbox Code Playgroud)

//创建数据库

public void createDataBase() throws IOException{
    //check if the database exists
    boolean databaseExist = checkDataBase();

    if(databaseExist){
        this.getWritableDatabase();
    }else{
        this.getReadableDatabase();
        try{
            copyDataBase();
        } catch (IOException e){
            throw new Error("Error copying database");
        }
    }// end if else dbExist
} // end createDataBase(). …
Run Code Online (Sandbox Code Playgroud)

database sqlite android database-update android-sqlite

5
推荐指数
1
解决办法
1万
查看次数