i am using Alert-dialog in Asynchronous task onPostexecute method.but my problem is when i come back to previous activity before the Asynchronous task completes.The Alertdialog (alert.show) is giving the following exception.The Alertdialog will appear on window but why this is not showing in other screens when i switch back.
Logcat Error:
02-27 05:03:05.283: E/AndroidRuntime(827): FATAL EXCEPTION: main
02-27 05:03:05.283: E/AndroidRuntime(827): android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@40f25058 is not valid; is your activity running?
02-27 05:03:05.283: E/AndroidRuntime(827): at android.view.ViewRootImpl.setView(ViewRootImpl.java:567)
02-27 05:03:05.283: E/AndroidRuntime(827): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:246)
02-27 05:03:05.283: E/AndroidRuntime(827): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
02-27 05:03:05.283: E/AndroidRuntime(827): at android.app.Dialog.show(Dialog.java:281)
02-27 05:03:05.283: E/AndroidRuntime(827): at android.app.AlertDialog$Builder.show(AlertDialog.java:951)
02-27 05:03:05.283: E/AndroidRuntime(827): at com.example.parentportal.Email$emailtask.onPostExecute(Email.java:119)
02-27 05:03:05.283: E/AndroidRuntime(827): at com.example.parentportal.Email$emailtask.onPostExecute(Email.java:1)
02-27 05:03:05.283: E/AndroidRuntime(827): at android.os.AsyncTask.finish(AsyncTask.java:631)
02-27 05:03:05.283: E/AndroidRuntime(827): at android.os.AsyncTask.access$600(AsyncTask.java:177)
02-27 05:03:05.283: E/AndroidRuntime(827): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
02-27 05:03:05.283: E/AndroidRuntime(827): at android.os.Handler.dispatchMessage(Handler.java:99)
02-27 05:03:05.283: E/AndroidRuntime(827): at android.os.Looper.loop(Looper.java:137)
02-27 05:03:05.283: E/AndroidRuntime(827): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-27 05:03:05.283: E/AndroidRuntime(827): at java.lang.reflect.Method.invokeNative(Native Method)
02-27 05:03:05.283: E/AndroidRuntime(827): at java.lang.reflect.Method.invoke(Method.java:511)
02-27 05:03:05.283: E/AndroidRuntime(827): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-27 05:03:05.283: E/AndroidRuntime(827): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-27 05:03:05.283: E/AndroidRuntime(827): at dalvik.system.NativeStart.main(Native Method)
Code
Context mContext = Email.this;
AlertDialog.Builder alert = new AlertDialog.Builder(mContext);
alert.setTitle("");
WebView wv = new WebView(mContext);
String html = "<h3>Message has been sent successfully</h3>";
wv.loadData(html, "text/html", "UTF-8");
alert.setView(wv);
// alert.setPositiveButton("Yes", new DialogInterface.OnClickListener(){
// public void onClick(DialogInterface dialog, int id){
//
// }
// });
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int id){
}
});
alert.show();
}