Android冻结了ProgressDialog

时间:2014-06-04 09:21:22

标签: android progressdialog loader

我想在加载新活动时添加进度对话框。它几乎一切都好,除了ProgressDialog冻结。

我的代码:

public class MyTask extends AsyncTask<String, String, String> {
    private Context context;
    private ProgressDialog progressDialog;

    public MyTask(Context context) {
        this.context = context;
    }

    @Override
    protected void onPreExecute() {
        progressDialog = new ProgressDialog(context);
        progressDialog.show();
    }

    @Override
    protected String doInBackground(String... params) {
        // Do your loading here
        return "finish";
    }

    @Override
    protected void onPostExecute(String result) {

        Intent editIntent = new Intent(
                "com.project.simplify.StartedReviewsEditActivity");
        editIntent.putExtra(EXTRA_OBJECT_ID, id);
        editIntent.putExtra("user", user);
        editIntent.putExtra("link", realLink);
        //review.putExtra("link", realLink);
        startActivity(editIntent);
        finish();
        progressDialog.dismiss();
    }
}

我在点击按钮时调用此方法:

editButton.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {
                MyTask myTask = new MyTask(StartedReviewsActivity.this);
                myTask.execute("parameter");

            }
        });

1 个答案:

答案 0 :(得分:2)

移动

 progressDialog.dismiss();

abovethis;

Intent editIntent = new Intent(
                "com.project.simplify.StartedReviewsEditActivity");
        editIntent.putExtra(EXTRA_OBJECT_ID, id);
        editIntent.putExtra("user", user);
        editIntent.putExtra("link", realLink);
        //review.putExtra("link", realLink);
        startActivity(editIntent);
        finish();

这样就可以了;

progressDialog.dismiss();
Intent editIntent = new Intent(
                "com.project.simplify.StartedReviewsEditActivity");
        editIntent.putExtra(EXTRA_OBJECT_ID, id);
        editIntent.putExtra("user", user);
        editIntent.putExtra("link", realLink);
        //review.putExtra("link", realLink);
        startActivity(editIntent);
        finish();

因为您首先完成了您的活动而没有首先解除导致冻结的progressdialog。 希望能帮助到你。干杯!