Friday, 6 September 2013

"android.view.WindowManager$BadTokenException: Unable to add window" on buider.show()

"android.view.WindowManager$BadTokenException: Unable to add window" on
buider.show()

From my main activity, I need to call an inner class(where I am making web
service call) and in a method within the class,I need to show AlertDialg
and dismiss it when OK button is pressed.
Things work perfectly for most of the times, but for few users it is
crashing on builder.show() and I can see
"android.view.WindowManager$BadTokenException: Unable to add window" from
crash log. Please suggest.
My code are pretty much like this:
public class login extends Activity{
public void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
new chkCubscription.execute("");
}
private class chkSubscription extends AsyncTask<String, Void, String>{
protected void onPostExecute(String result){
AlertDialog.Builder builder = new AlertDialog.Builder(login.this);
builder.setCancelable(true);
builder.setMessage(sucObject);
builder.setInverseBackgroundForced(true);
builder.setNeutralButton("Ok",new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){
dialog.dismiss();
}
});
builder.show();
}
}
}

No comments:

Post a Comment