Android Alertdialog Box Windowmanager$badtokenexception Problem
I am using the the following code for a context menu and then if user chose delete, a dialog massage will appear. infos.setOnCreateContextMenuListener(new OnCreateContextMenuListen
Solution 1:
I believe the problem could be on this line:
AlertDialog.Builderbuilder=newAlertDialog.Builder(this);
Try modifying it to:
AlertDialog.Builderbuilder=newAlertDialog.Builder(MyActivityName.this);
Replacing MyActivityName with the name of your activity.
Did that fix the error?
Solution 2:
It should be AlertDialog.Builder builder = new AlertDialog.Builder(this.getParent());
Because the activity is in a tabactivity within another tabactivity.
Solution 3:
I was getting the same error. I changed
AlertDialog.Builderbuilder=newAlertDialog.Builder(this);
to
AlertDialog.Builderbuilder=newAlertDialog.Builder(MainActivity.this);
Its working fine now. Thanks.
Solution 4:
Kotlin
Change from this:
val builder: AlertDialog.Builder = AlertDialog.Builder(this)
to
val builder: AlertDialog.Builder = AlertDialog.Builder(this@MainActivity)
Post a Comment for "Android Alertdialog Box Windowmanager$badtokenexception Problem"