升级数据库时显示进度对话框
我的应用程序的下一个版本需要升级数据库,这需要相当多的时间。我想显示一个进度对话框来向用户更新进度。问题是,我不太清楚如何以及在哪里创建对话框。
我的基本设置是我有一个基本上是闪屏的活动。我想在这个屏幕上显示进度。我有一个单独的 DbAdapter.java 文件,其中 DatabaseHelper 类扩展了 SQLiteOpenHelper,我在其中重写了 onUpgrade (升级部分工作正常)。
我尝试了几个不同的地方来实现进度对话框,但我似乎没有找到正确的位置。我尝试将上下文从闪屏活动传递到 onUpgrade,但是当 onUpgrade 运行时,它似乎是从我的 ContentProvider 获取上下文。
有谁有一个关于如何在升级数据库时显示进度对话框的好例子?
The next version of my app needs to upgrade the database and this takes quite a bit of time. I'd like to show a progressDialog to update the user on the progress. Problem is, I can't quite figure out how and where to create the dialog.
My basic setup is that I have an activity which is essentially a splashscreen. It's on this screen I would like to show the progress. I have a separate DbAdapter.java file where a DatabaseHelper class extends SQLiteOpenHelper, where I override onUpgrade (the upgrade part is working fine).
I've tried a few different places to implement the progress dialog, but I don't seem to find the right spot. I tried passing context from my splashscreen activity to onUpgrade, but when onUpgrade runs it seems to be getting the context from my ContentProvider instead.
Does anyone have a good example of how to display a progress dialog when upgrading a database?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要实现一个
AsyncTask
。示例:然后您只需调用
new YourAsyncTask().execute();
您可以在此处阅读有关 AsyncTask 的更多信息:http://developer.android.com/reference/android/os/AsyncTask.html
You need to implement an
AsyncTask
. Example:Then you just have to call
new YourAsyncTask().execute();
You can read more about AsyncTask here: http://developer.android.com/reference/android/os/AsyncTask.html