-1

异步任务在运行时在触摸屏幕时开始取消。我已经在三星 pop中使用android 2.3.6测试了我的应用程序。在这个移动设备中,异步任务在运行时触摸屏幕时不会被取消。但是虽然我在Sony u 中使用 android 4.0.1对其进行了测试 我触摸屏幕异步任务已被取消。我试图用异步状态覆盖触摸事件。但它没有得到修复。我们该如何解决这个问题?

4

1 回答 1

2

我找到了解决方案

我用

dialog.setCanceledOnTouchOutside(false); dialog.setCancelable(false);

public class getcatogry extends AsyncTask<String, Void, Void> {

    private final ProgressDialog dialog = new ProgressDialog(
            MainActivity.this);

    // can use UI thread here
    protected void onPreExecute() {
        this.dialog.setMessage("Loading...");
        this.dialog.show();
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
    }

    // automatically done on worker thread (separate from UI thread)
    protected Void doInBackground(final String... args) {
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);






        return null;
    }

    // can use UI thread here
    protected void onPostExecute(final Void unused) {
        if (this.dialog.isShowing()) {
            this.dialog.dismiss();




        }
        // reset the output view by retrieving the new data
        // (note, this is a naive example, in the real world it might make
        // sense
        // to have a cache of the data and just append to what is already
        // there, or such
        // in order to cut down on expensive database operations)
        // new SelectDataTask().execute();
    }
}

这样,即使在后按或触摸异步任务时,异步任务也不会被取消

于 2012-11-09T09:08:14.757 回答