开发者

Frozen progress dialog Android

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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜