在Android应用程序启动中使用ProgressDialog

发布于 2024-11-05 13:32:01 字数 1519 浏览 0 评论 0原文

如何在应用程序启动期间显示进度对话框。我在 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 技术交流群。

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

发布评论

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

评论(1

爺獨霸怡葒院 2024-11-12 13:32:01

如果您想在获取数据或类似内容时显示进度对话框,则需要使用带有 ProgressDialog 边界的 AsyncTask 。请参阅此处的示例。

If you want to show a progress dialog, while fetching data or something like this, you need to use AsyncTask with ProgressDialog bounded. See an example here.

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