将文件从资产复制到数据文件夹后,首次在 Android 中不显示数据

发布于 2024-09-03 11:17:58 字数 1016 浏览 3 评论 0原文

我使用了这里的代码提示< /a> 将预填充的数据文件复制到目标并在异步任务中处理此问题。

启动应用程序时,它会出现错误并第一次关闭,再次启动时无需任何更改,它工作得很好。 因此,第一次复制文件后,会出现错误,但之后就没有问题了。

private class CopyDatabase extends AsyncTask<String, Void, Boolean> {
    private final ProgressDialog dialog = new ProgressDialog(BabyNames.this);
    protected void onPreExecute() {
        this.dialog.setMessage("Loading...");
        this.dialog.show();
    }

    @Override
    protected Boolean doInBackground(String... params) {
        // TODO Auto-generated method stub
        try {
            namesDBSQLHelper.createDatabase();
            return null;
        } catch(IOException ioe){
            ioe.printStackTrace();
        }
        return null;

    }

    protected void onPostExecute(final Boolean success){
        if (this.dialog.isShowing()){
            this.dialog.dismiss();
        }
    }
}

I have used the code tip from here to copy a pre-filled data file to the target and handled this in a asynch task.

On starting the application it gives error and shuts down first time, starting again without any change it works perfectly fine.
So first time after the file is copied, the error comes but after that no issues.

private class CopyDatabase extends AsyncTask<String, Void, Boolean> {
    private final ProgressDialog dialog = new ProgressDialog(BabyNames.this);
    protected void onPreExecute() {
        this.dialog.setMessage("Loading...");
        this.dialog.show();
    }

    @Override
    protected Boolean doInBackground(String... params) {
        // TODO Auto-generated method stub
        try {
            namesDBSQLHelper.createDatabase();
            return null;
        } catch(IOException ioe){
            ioe.printStackTrace();
        }
        return null;

    }

    protected void onPostExecute(final Boolean success){
        if (this.dialog.isShowing()){
            this.dialog.dismiss();
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

听风吹 2024-09-10 11:17:58

尝试通过这种方式复制数据库。它看起来与您提供的链接的答案相同,但有一些不同。
数据库不从资产复制

Try copying database by this way.It looks same as the answer of the link provided by you but it has some difference.
Database not copying from assets

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文