【问题标题】:Using ProgressDialog in android application startup在 android 应用程序启动中使用 ProgressDialog
【发布时间】:2011-08-21 13:17:58
【问题描述】:

如何在应用程序启动期间显示progressDialog。我在 oncreate 方法中显示了一个 progressDialog,并且在启动应用程序时它没有显示。

我经历过这个: ProgressDialog not showing until after function finishes

我已尝试针对上述问题解释的解决方案。但它并不完美。

这是我的代码:

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 在完成初始设置之前出现。

谁能建议我如何建立此功能。它是一个表格布局,每个选项卡都有列表视图。

【问题讨论】:

  • 这里为什么需要 ProgressDialog。你在这里没有做任何后台操作。您不需要 ProgressDialog 来启动服务。
  • 对不起,我没有得到你!我的仪表板是在服务连接时创建的。一些方法在服务下运行以获取初始数据。我正在为我的标签布局使用基于活动的标签。

标签: android progressdialog android-progressbar


【解决方案1】:

如果你想显示一个进度对话框,在获取数据或类似的东西时,你需要使用AsyncTask和ProgressDialog有界。查看示例here。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-26
    • 1970-01-01
    • 1970-01-01
    • 2012-05-12
    相关资源
    最近更新 更多