cannot display progress bar at the time of loading another Activity in Android

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


ANSWERS:


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.


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;
    }


 MORE:


 ? Is there a black progress bar to be visible on a white background?
 ? How to remove progress bar number at the bottom part of the progress bar?
 ? Vertical progress bar in android
 ? Custom indeterminate progress bar
 ? Progress bar inconvertable types; cannot cast error
 ? Remove progress bar from published document in MATLAB
 ? What is the basic idea behind programming a progress/status bar in MATLAB?
 ? Text progress bar in Matlab
 ? MATLAB update waitbar
 ? xlsread and waitbar MATLAB