将文件从资产复制到数据文件夹后,首次在 Android 中不显示数据
我使用了这里的代码提示< /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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试通过这种方式复制数据库。它看起来与您提供的链接的答案相同,但有一些不同。
数据库不从资产复制
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