Hi in my app there is an Async Task to read contact detail(which take a little bit time).It does well , but what the problem is when i cancel the Async Task before it completes,fetching details my app get crash.So i was think that make the app to exit when i cancel the Async Task.I search the web and find some method but it did not worked,so how can i exit my app when cancelling an async task? My Asyn Task code(normal code)
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();
}
}