Database not getting copied properly in OnePlus Two

前端 未结 3 969
再見小時候
再見小時候 2020-12-28 15:51

I am creating an Android Application and I am using sqlite database in it. for that I have placed a sqlite file in assets folder of project and I am copying this file to pho

3条回答
  •  情书的邮戳
    2020-12-28 16:07

    I have found solution for this, I have used below function :

    public void createDb() {
            boolean dbExist = checkDataBase();
    
            if (dbExist) {
                // do nothing - database already exist
            } else {
                // call close() for properly copy database file
                this.getReadableDatabase().close();
                try {
                    copyDataBase();
                } catch (IOException e) {
                    e.printStackTrace();
                    throw new Error("Error copying database");
                }
            }
        }
    

    As per this post we need to call close() and you can push database to Oneplus two devices also.

提交回复
热议问题