Today, when using the Android Pop-up dialog, I reported a unable to add window error, and my code is as follows
New Alertdialog.builder (Getapplicationcontext ()). Settitle ("hint"). Setmessage ("Are you sure you want to delete it?"). "). Setpositivebutton (" OK ", new Dialoginterface.onclicklistener () {public void OnClick (dialoginterface dialog, int which) {}}} ). Setnegativebutton ("Cancel", new Dialoginterface.onclicklistener () { @Override public void OnClick (Dialoginterface dialog, int which) { dialog.cancel (); } }). Show ();
look at the code carefully, everything is normal, there is no error, but we ignore only activity to add window, so the above code if placed in the OnCreate () method, we put Builder (Getapplicationcontext ()) changed to Builder (This), if we are using it in other methods, we cannot use Getapplicationcontext () and should use Builder (activity.this)
Android uses pop-up dialog to report unable to add window error