Original Blog Address: http://aijiawang-126-com.javaeye.com/blog/662336
In activity Newspinner I passed mcontext in, but out of android.view.windowmanager$badtokenexception:unable to add window-Token Null is not a application This error, refer to the reach of the article finally fix.
[Java]View Plaincopy
- Private Context Mcontext;
- @Override
- protected void OnCreate (Bundle savedinstancestate) {mcontext = Getapplicationcontext ();
- System.out.println ("mcontext=" + mcontext);
- }
[Java]View Plaincopy
- New Alertdialog.builder (Mcontext)
- . SetIcon (Android. R.drawable.ic_dialog_alert)
- . Settitle ("warnning")
- . Setmessage (
- "You forget to write the message. Do you want to fill out it?? ")
- . Setpositivebutton ("Yes", Positivelistener). Setnegativebutton (
- "No", Negativelistener). Create (). Show ();
This error is caused by the new Alertdialog.builder (Mcontext), although the parameter here is Alertdialog.builder (context context) However, we cannot use the context obtained by Getapplicationcontext () and must use activity because there is only one activity to add a form.
Workaround: Populate the parameters in the new Alertdialog.builder (context context) with activity.this (the activity is the name of your activity) to create a dialog correctly.
[Java]View Plaincopy
- New Alertdialog.builder (myactivity. This)
- . SetIcon (Android. R.drawable.ic_dialog_alert)
- . Settitle ("warnning")
- . Setmessage (
- "You forget to write the message. Do you want to fill out it?? ")
- . Setpositivebutton ("Yes", Positivelistener). Setnegativebutton (
- "No", Negativelistener). Create (). Show ();
- Previous Android custom title bar ProgressBar
- Next android screen switch a little feeling
android.view.windowmanager$badtokenexception:unable to add window--token null was not for an application