Android中加载另一个Activity时无法显示进度条

发布于 2024-08-26 01:29:29 字数 846 浏览 5 评论 0原文

这可能是一个简单的问题,但我是初学者,我需要你的建议。 我有两个活动 A1 和 A2。当我单击 A1 屏幕上的图像时,我必须显示进度条,直到出现 A2 屏幕(A2 活动有大量任务要做)。我尝试过

 image.setOnClickListener(new ImageView.OnClickListener() {

            public void onClick(View v)
            {

             myProgressDialog = ProgressDialog.show(A1.this,     
                        "Please wait...", "Loading...", true);

              new Thread() {
                   public void run() {
                        try{



                        Intent i = new Intent(A1.this,.A2.class);
                        startActivity(i);


                        } catch (Exception e) {  }
                        // Dismiss the Dialog
                        myProgressDialog.dismiss();
                   }
              }.start();


             }
        });

这无法显示进度条。我知道我我犯了一个错误,但我不明白

This may be a simple question but i am a beginner ,i need your suggestion on this.
i have two Activities A1 and A2 .When i click the image on A1 screen i have to display progress bar until A2 screen appears(A2 activity has huge task to do).I tried

 image.setOnClickListener(new ImageView.OnClickListener() {

            public void onClick(View v)
            {

             myProgressDialog = ProgressDialog.show(A1.this,     
                        "Please wait...", "Loading...", true);

              new Thread() {
                   public void run() {
                        try{



                        Intent i = new Intent(A1.this,.A2.class);
                        startActivity(i);


                        } catch (Exception e) {  }
                        // Dismiss the Dialog
                        myProgressDialog.dismiss();
                   }
              }.start();


             }
        });

This couldn't display progress bar .I know that i am making a mistake but i couldn't figure out

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

潇烟暮雨 2024-09-02 01:29:29

最好的办法是在 A2 活动中显示进度对话框。一旦启动一个活动,前一个活动就会进入后台,因此进度对话框无论如何都不会显示。

Your best bet is to show the progress dialog in the A2 activity. Once you start an Activity, the previous activity goes into the background, so the progress dialog wouldn't display anyway.

看海 2024-09-02 01:29:29

首先,需要在单独的线程上调用进度对话框。使用 AsyncTask<>显示对话框并同时在后台执行一些操作。示例代码可能是这样的

class hello extends AsyncTask<Void,Void,Void>
{
       ProgressDialog dialog=null;
       Intent i;

   @Override
   protected void onPreExecute() 
   {


           dialog=ProgressDialog.show(A1.this,"PLEASE WAIT","LOADING CONTENTS  ..",true);
   }

    @Override
    protected void onPostExecute(Void result) 
    {
            if(dialog.isShowing())
                    {
                       dialog.dismiss();
                       startActivity(i);
                    }           
    }

    @Override
    protected Void doInBackground(Void... params) 
    {
        i = new Intent(A1.this,.A2.class);
                    return null;
    }

First of all , the progress dialog needs to be called on a separate thread . Use the AsyncTask<> to display the dialog and at the same time perform some operation in the background . A sample code might be something like this

class hello extends AsyncTask<Void,Void,Void>
{
       ProgressDialog dialog=null;
       Intent i;

   @Override
   protected void onPreExecute() 
   {


           dialog=ProgressDialog.show(A1.this,"PLEASE WAIT","LOADING CONTENTS  ..",true);
   }

    @Override
    protected void onPostExecute(Void result) 
    {
            if(dialog.isShowing())
                    {
                       dialog.dismiss();
                       startActivity(i);
                    }           
    }

    @Override
    protected Void doInBackground(Void... params) 
    {
        i = new Intent(A1.this,.A2.class);
                    return null;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文