When alertdialog show is used, an error is reported:
E/androidruntime (921): Android. View. windowmanager $ badtokenexception: unable to add window -- token null is not for an application
Alertdialog. Builder; builder = new alertdialog. Builder (This. getapplicationcontext ()); Layoutinflater Inflater = getlayoutinflater (); // (layoutinflater) mycontext. getsystemservice (layout_inflater_service); view layout = Inflater. inflate (R. layout. my_dialog, (viewgroup) findviewbyid (R. id. my_dialog_layout_root); builder. setview (layout); // builder. create (); builder. show ();
The problem lies in
This. getapplicationcontext ()
. This is normal.
Refer:
Http://stackoverflow.com/questions/2634991/android-1-6-android-view-windowmanagerbadtokenexception-unable-to-add-window
Http://lipeng88213.iteye.com/blog/835180
Http://aijiawang-126-com.iteye.com/blog/662336