I could fix the problem by de-referencing the static variables of the activity in onDestroy() method.
On Dec 16, 2:42 am, Yousuf Syed <[email protected]> wrote: > Check your code for context and change getApplicationContext(); to this > > I Guess your context assignment is > Context context = getApplicationContext(); // this give you the > bad token error. > change it to: > *Context context = this;* // this assignment will remove your bad > token exception. > > > > On Tue, Dec 15, 2009 at 8:27 AM, Ronin <[email protected]> wrote: > > Hi, > > > I am trying to write a small game application in Android. > > Following error is seen when I try to do showDialog(). > > > When I launch the emulator and start the game the first time it works > > fine. Then, the second time, it fails with the error. And 3rd, 5th, > > 7th time it works fine. Whereas it fails 4th,6th, 8th time and so > > on... > > > I do not have any clue why it is happening. Please help. May be the > > exception is cleaning up something and the next time the application > > works fine. > > > Code snippet is below. I am not doing any cleanup in onDestroy() > > method as of now. > > > ------ Code GameActivity.onCreateDialog() start ------ > > public Dialog onCreateDialog(int id) > > { > > AlertDialog ad = null; > > AlertDialog.Builder builder = new AlertDialog.Builder > > (this); > > ad = builder.create(); > > > this.id = id; > > > if(id == Consts.WINNER_DIALOG_ID) > > ad.setMessage(player[winnerId]+" is the > > winner"); > > else if(id == Consts.TIE_DIALOG_ID) > > ad.setMessage("It's a tie"); > > > ad.setButton("OK", new DialogInterface.OnClickListener > > () { > > public void onClick(DialogInterface di, int i) > > { > > ((GameActivity)mContext).finish(); > > } > > }); > > return ad; > > } > > ------ Code GameActivity.onCreateDialog() end ------ > > > ------ Exception start here ------ > > 12-14 08:25:40.166: WARN/WindowManager(52): Attempted to add > > application window with unknown token HistoryRecord{433b63b8 > > {com.abcd.android.examples/com.abcd.android.examples.GameActivity}}. > > Aborting. > > 12-14 08:25:40.176: DEBUG/AndroidRuntime(169): Shutting down VM > > 12-14 08:25:40.186: WARN/dalvikvm(169): threadid=3: thread exiting > > with uncaught exception (group=0x4000fe68) > > 12-14 08:25:40.186: ERROR/AndroidRuntime(169): Uncaught handler: > > thread main exiting due to uncaught exception > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): > > android.view.WindowManager$BadTokenException: Unable to add window -- > > token android.os.binderpr...@433aaaa8 is not valid; is your activity > > running? > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > android.view.ViewRoot.setView(ViewRoot.java:384) > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177) > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > android.view.WindowManagerImpl.addView(WindowManagerImpl.java:90) > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > android.view.Window$LocalWindowManager.addView(Window.java:393) > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > android.app.Dialog.show(Dialog.java:212) > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > android.app.Activity.showDialog(Activity.java:2277) > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > com.abcd.android.examples.ImageAdapter.clicked(ImageAdapter.java:115) > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > com.abcd.android.examples.ImageAdapter$1.onClick(ImageAdapter.java: > > 149) > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > android.view.View.performClick(View.java:2129) > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > android.view.View.onTouchEvent(View.java:3543) > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > android.view.View.dispatchTouchEvent(View.java:3198) > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857) > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857) > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857) > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857) > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857) > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > com.android.internal.policy.impl.PhoneWindow > > $DecorView.superDispatchTouchEvent(PhoneWindow.java:1593) > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent > > (PhoneWindow.java:1089) > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > android.app.Activity.dispatchTouchEvent(Activity.java:1871) > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > com.android.internal.policy.impl.PhoneWindow > > $DecorView.dispatchTouchEvent(PhoneWindow.java:1577) > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > android.view.ViewRoot.handleMessage(ViewRoot.java:1140) > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > android.os.Handler.dispatchMessage(Handler.java:88) > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > android.os.Looper.loop(Looper.java:123) > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > android.app.ActivityThread.main(ActivityThread.java:3739) > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > java.lang.reflect.Method.invokeNative(Native Method) > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > java.lang.reflect.Method.invoke(Method.java:515) > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run > > (ZygoteInit.java:739) > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497) > > 12-14 08:25:40.216: ERROR/AndroidRuntime(169): at > > dalvik.system.NativeStart.main(Native Method) > > ------ Exception end here ------ > > > -- > > You received this message because you are subscribed to the Google > > Groups "Android Beginners" group. > > To post to this group, send email to [email protected] > > To unsubscribe from this group, send email to > > [email protected]<android-beginners%2Bunsubscr > > [email protected]> > > For more options, visit this group at > >http://groups.google.com/group/android-beginners?hl=en -- You received this message because you are subscribed to the Google Groups "Android Beginners" group. NEW! Try asking and tagging your question on Stack Overflow at http://stackoverflow.com/questions/tagged/android To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en

