Android 开始新活动时的进度对话框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2231438/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:04:07  来源:igfitidea点击:

Progress Dialog while starting new activity

android

提问by Andy

this button is shown on my start activity. After pressing it a new activity will be launched but this takes some time cause on initialization of that new activity some data is gathered from the Internet. This works half. The progress dialoge is shown but the progress wheel is not spinning.

此按钮显示在我的开始活动中。按下后将启动一个新活动,但这需要一些时间,因为在初始化该新活动时会从 Internet 收集一些数据。这工作一半。显示进度对话框,但进度轮未旋转。

Can somebody tell me why this happens?

有人能告诉我为什么会这样吗?

  Button b4 = (Button) findViewById(R.id.Button01);
      b4.setOnClickListener(new View.OnClickListener() {
          public void onClick (View view) {    
           final ProgressDialog pd = ProgressDialog.show(pak.this, 
                         "", "Working..", true);

            new Thread(new Runnable(){
             public void run(){
              Intent intent = new Intent();
                 intent.setClassName("sxe.pak", "sxe.pak.List");
                 startActivity(intent);               
              pd.dismiss();
                }
           }).start();

          }
   });

thx

谢谢

采纳答案by Mark B

You need to show the progress dialog at the very start of your 2nd Activity, not your first one. And you need to do your data download work in an AsyncTask.

您需要在第二个活动开始时显示进度对话框,而不是第一个。并且您需要在 AsyncTask 中完成数据下载工作。

See my answer to this for more info:

有关更多信息,请参阅我对此的回答:

Android SplashScreen

安卓启动画面