tags:

views:

495

answers:

1

Hi all, 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.

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

+1  A: 

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.

See my answer to this for more info:

http://stackoverflow.com/questions/1979524/android-splashscreen

mbaird
Good answer, but I would prefer Thread to AsyncTask as long as the thread dont need to use the UI thread.
sandis
Hi mbaird, thx for your answer. I'm aware of the possibility to use AsyncTask to to asynchronous work but in my case its not usable (or i don't know how) cause i want to start a new Activity. Starting the progress dialog at the very start of the 2nd Activity is not an option, i tried that already without luck, cause the first Activity is shown until the start of the second one is done.If i hit the button, the button changes its color and then the process dialog is shown like i expect it ONLY the wheel is not spinning. Thats the only problem.
Andy
@Andy, the progress dialog is not spinning because you are doing work in the UI thread. Move your download work to a separate thread via AsyncTask or just a Thread or Runnable. Again, if you look at the answer I gave above, and try to copy what's going on in the onCreate() method of my answer to that question in the onCreate() method of your 2nd activity, I promise it will work.
mbaird
hey mbaird, ok, it took some time but now everything works like expected. i had to rewrite some parts of my application to use AsyncTask properly. Thx for your help, it took me in the right direction. :) (finally you get my vote ;) )
Andy