我有AsyncTask,在它执行之后我在onPostExecute中显示一些警报拨号。它工作正常。 但是,如果在doInBackground期间停止活动,则在执行AsyncTask之后,如果显示dialoge,则活动重启后不会显示警报dialoge,并且活动布局会以相同的方式变暗。
public class CheckPin extends AsyncTask<String, Void, Integer>{
@Override
protected Integer doInBackground(String... uri) {
publishProgress();
//some code
return ret;
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
showDialog(CHECKING_PIN);
}
@Override
protected void onPostExecute(Integer result) {
super.onPostExecute(result);
dismissDialog(CHECKING_PIN);
AlertDialog.Builder mBuilder = new AlertDialog.Builder(EnterPin.this);
mBuilder.setMessage("Error")
.setCancelable(false)
.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
});
final AlertDialog mAlert = mBuilder.create();
mAlert.show();
break;
}
}
答案 0 :(得分:0)
AlertDialog.Builder mBuilder = new AlertDialog.Builder(CLASSNAME.this);
mBuilder.setTitle("Error message")
.setMessage("You've encountered a problem.")
.setCancelable(false)
.setPositiveButton("Done", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//do something...
}
})
.create().show();