我试图在 onCancelled 上的 AsyncTask 中显示一个 AlertDialog。我的任务正在正常停止,但没有出现对话框。下面是我的代码......需要帮助。谢谢...
public class getWebPage extends AsyncTask<String, Integer, String> {
protected void onPreExecute(String f) {
// TODO Setting up variables
f = "f";
}
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
Looper.prepare();
DefaultHttpClient urlClient = new DefaultHttpClient();
HttpGet getHtml = new HttpGet(PAGE_URL);
ResponseHandler<String> resHandler = new BasicResponseHandler();
try {
String htmlPage = urlClient.execute(getHtml, resHandler);
Log.d("Html Page", htmlPage);
confessionsPage = new File(getApplicationContext().getFilesDir(), "ConfessionsPage.html");
if (!confessionsPage.exists()) {
confessionsPage.createNewFile();
}
writer = new PrintWriter(confessionsPage, "UTF-8");
writer.print(htmlPage.replace("<!--", "").replace("-->", ""));
writer.flush();
writer.close();
Document doc = Jsoup.parse(confessionsPage, "UTF-8", "http://www.facebook.com/");
if (doc.title().contains("Welcome to Facebook")) {
aDialog = new AlertDialog.Builder(OpeningActivity.this).create();
aDialog.setTitle("Restricted Access");
aDialog.setMessage("Looks like your Confessions Page only allows login access. You may be logged in right now, but the app" +
" can't. Tell your page admin to allow non-logged in access for your confessions page.");
aDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
aDialog.dismiss();
}
});
getWebPage.this.cancel(true);
}
这是我取消的方法:
@Override
protected void onCancelled() {
// TODO Auto-generated method stub
super.onCancelled();
aDialog.show();
}