I'm not sure how to reproduce the problem, but it is probably safer to use the Actvity's build-in dialog methods to manage dialogs...I would change the code to use the following built-in activity methods:
onCreateDialog() - http://developer.android.com/reference/android/app/Activity.html#onCreateDialog%28int,%20android.os.Bundle%29 onPrepareDialog() - http://developer.android.com/reference/android/app/Activity.html#onPrepareDialog%28int,%20android.app.Dialog,%20android.os.Bundle%29 showDialog() - http://developer.android.com/reference/android/app/Activity.html#showDialog%28int%29 dismissDialog() - http://developer.android.com/reference/android/app/Activity.html#dismissDialog%28int%29 removeDialog() - http://developer.android.com/reference/android/app/Activity.html#removeDialog%28int%29 Thanks, Justin Anderson MagouyaWare Developer http://sites.google.com/site/magouyaware On Fri, Mar 11, 2011 at 5:22 AM, hoyski <[email protected]> wrote: > I'm getting a few reports in the Market of my users experiencing a > WindowManager$BadTokenException from an AlertBuilder.Builder.show() > call. (Full stack trace and relevant code below.) I've read what can > cause this to happen but no matter what I try, I can't cause the > exception to be thrown on any of my emulators or my Nexus One. > > I've tried hitting the Back and Home buttons just as the dialog is > about to be displayed, changing the phone's orientation, and launching > multiple other apps in an attempt to get my app paused/resumed. > > Anyone have any ideas on other actions I can take to try and cause the > exception? > > Thanks, > Dave > > Stack Trace: > > android.view.WindowManager$BadTokenException: Unable to add window -- > token android.os.BinderProxy@46042700 is not valid; is your activity > running? > at android.view.ViewRoot.setView(ViewRoot.java:509) > at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177) > at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91) > at android.view.Window$LocalWindowManager.addView(Window.java:424) > at android.app.Dialog.show(Dialog.java:241) > at android.app.AlertDialog$Builder.show(AlertDialog.java:802) > at com.hoyski.androidsquares.Squares.showGameOverDialog(Squares.java: > 556) > at com.hoyski.androidsquares.Squares.computerMoveOnce(Squares.java: > 475) > at com.hoyski.androidsquares.Squares.run(Squares.java:666) > at android.os.Handler.handleCallback(Handler.java:587) > at android.os.Handler.dispatchMessage(Handler.java:92) > at android.os.Looper.loop(Looper.java:144) > at android.app.ActivityThread.main(ActivityThread.java:4937) > at java.lang.reflect.Method.invokeNative(Native Method) > at java.lang.reflect.Method.invoke(Method.java:521) > at com.android.internal.os.ZygoteInit > $MethodAndArgsCaller.run(ZygoteInit.java:868) > at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) > at dalvik.system.NativeStart.main(Native Method) > > > Relevant Code: > > private void showGameOverDialog() { > > AlertDialog.Builder gameOverBldr = new AlertDialog.Builder(this); > gameOverBldr.setPositiveButton("OK", > new DialogInterface.OnClickListener() { > @Override > public void onClick(DialogInterface dialog, int which) { > dialog.cancel(); > } > }); > > String title = "Game Over"; > String msg = "... logic to build message snipped..."; > > gameOverBldr.setTitle(title); > gameOverBldr.setMessage(msg); > > gameOverBldr.show(); > } > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

