嗨,在我的应用程序中有一个异步任务来读取联系人详细信息(这需要一点时间)。它做得很好,但是当我在完成之前取消异步任务时,问题是什么,获取详细信息我的应用程序崩溃了。所以我我认为当我取消异步任务时会使应用程序退出。我在网上搜索并找到了一些方法但它没有用,那么在取消异步任务时如何退出我的应用程序? 我的 Asyn 任务代码(普通代码)
public class FetchingContact extends AsyncTask<String, Void, Void> {
private final ProgressDialog dialog = new ProgressDialog(
MobiMailActivity.this);
// can use UI thread here
protected void onPreExecute() {
this.dialog.setMessage("Fetching Contact...");
this.dialog.show();
}
// automatically done on worker thread (separate from UI thread)
protected Void doInBackground(final String... args) {
readContact();
if (isCancelled ()) {
finish();
}
return null;
}
// can use UI thread here
protected void onPostExecute(final Void unused) {
if (this.dialog.isShowing()) {
this.dialog.dismiss();
CharSequence test=sam;
// search_sort.setText(test);
check(test);
}
// 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();
}
}