0

This is my code

public void DownloadROM(View view) {
          progressDialog = new ProgressDialog(ROMManager.this);
          progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
          progressDialog.setMessage("Downloading ROM Repository\nPlease standby");
          progressDialog.show();
          gotoList(view);
          Log.v("ROMManager", "Showing download List");  
  } 

  public void gotoList(final View view){
          Thread background = new Thread(new Runnable(){ 
                  public void run() {
                  Intent i = new Intent(ROMManager.this, DownloadList.class);
                      startActivity(i);
          }
          });
          background.start();
  }

Problem is that when I call DownloadROM, the progress dialog appears, but the Spinner doesn't move, this is my last try, before was only 1 method Thanks.

GoZoner
  • 67,920
  • 20
  • 95
  • 145
user809486
  • 888
  • 1
  • 7
  • 15

2 Answers2

2

Use an AsyncTask.

DownloadTask extends AsyncTask<Type, Void, Type>
    @Override
    protected void onPreExecute() {
    dialog = ProgressDialog.show(view.getContext(), "Loading", "Loading");
    }
    @Override
    protected Type doInBackground(Type... params) {
        //Do something with the data
        return data;
    }

    @Override
    protected void onPostExecute(Type result) {
        dialog.dismiss();
        //Return the data
    }

Documentation can be found here. And examples can be found here.

Stefan Bossbaly
  • 6,682
  • 9
  • 53
  • 82
1

Not sure but maybe the problem is that the activity who launched the progressDialog isn't in "focus" anymore but DownloadList activity is.

Maybe you can try handle the progressDialog in the DownloadList Activity.

Edit: 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.

Source

Community
  • 1
  • 1
BrainCrash
  • 12,992
  • 3
  • 32
  • 38
  • Thanks for answer. Tried that way, just made things harder, and it just don't worked. Weird thing it's that it shows progressbar, but dont moves .. i guess startActivity it's doing that – user809486 Jun 22 '11 at 03:38
  • Thanks, AsyncTask it's really good, but in this situation i don't know how to implement it, because Second activity it's a ListActivity. – user809486 Jun 22 '11 at 14:04
  • Checking on DownloadList, i find the answer, without using asyncTask, thanks. – user809486 Jun 22 '11 at 15:20