在Android应用程序启动中使用ProgressDialog
如何在应用程序启动期间显示进度对话框。我在 oncreate 方法中显示了一个进度对话框,但在启动应用程序时它没有显示。
我经历过这个: ProgressDialog 在函数完成后才显示
我已经尝试了解释的解决方案上述问题。但它的工作并不完美。
这是我的代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dash);
progressDialog = ProgressDialog.show(this, "", "Loading...");
//Run background UI thread
Thread laucherThread = new Thread(new Runnable() {
public void run() {
Looper.prepare(); //I had to include this to prevent force close error
startService(new Intent(DroidChirp.this,ChirpService.class));
doBindService();
Log.e(MY_DEBUG_TAG, "Prepairing to close the dialog");
runOnUiThread(new Runnable() {
public void run() {
progressDialog.dismiss();
}
});
Log.e(MY_DEBUG_TAG, "Closed the dialog");
}
});
laucherThread.start();
}
我需要做的是:
- 显示进度对话框,直到完成所有初始设置
我面临的问题:
- ProgressDialog 是启动时不显示。
- 启动应用程序时出现延迟(有时显示空白)。
- 在完成初始设置之前会出现 ProgressDialog。
谁能建议我如何建立这个功能。它是一个表格布局,每个选项卡都有列表视图。
How can I show a progressDialog during the start up of an application. I have shown a progressDialog in the oncreate method and its not showing when launching the application.
I have gone through this:
ProgressDialog not showing until after function finishes
I have tried the solution explained for the above question. But its not working perfectly.
Here is my code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dash);
progressDialog = ProgressDialog.show(this, "", "Loading...");
//Run background UI thread
Thread laucherThread = new Thread(new Runnable() {
public void run() {
Looper.prepare(); //I had to include this to prevent force close error
startService(new Intent(DroidChirp.this,ChirpService.class));
doBindService();
Log.e(MY_DEBUG_TAG, "Prepairing to close the dialog");
runOnUiThread(new Runnable() {
public void run() {
progressDialog.dismiss();
}
});
Log.e(MY_DEBUG_TAG, "Closed the dialog");
}
});
laucherThread.start();
}
What I need to do is:
- Show a progressDialog until all the initial setup is finished
Issues I am facing :
- ProgressDialog is not showing at the start up.
- There is a delay when starting the application(Showing blank for sometime).
- ProgressDialog appears just before finishing the initial setup.
Can anyone suggest me how can I establish this feature. Its a tablelayout with list view for each tab.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想在获取数据或类似内容时显示进度对话框,则需要使用带有
ProgressDialog
边界的AsyncTask
。请参阅此处的示例。If you want to show a progress dialog, while fetching data or something like this, you need to use
AsyncTask
withProgressDialog
bounded. See an example here.