Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6084477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:31:36+00:00 2026-05-23T11:31:36+00:00

I have an issue where I receive a BadTokenException when the screen times out,

  • 0

I have an issue where I receive a BadTokenException when the screen times out, and then the user returns to my application. I have a button which opens up a ContextMenu when clicked.

It works fine normally, but when the user lets the screen time out, and then returns to the application, a BadTokenException is thrown.

07-01 14:46:42.763: WARN/WindowManager(1105): Attempted to add window with token that is a sub-window: android.os.BinderProxy@44af17c8.  Aborting.
    07-01 14:46:42.771: WARN/System.err(1725):     at android.view.ViewGroup.showContextMenuForChild(ViewGroup.java:459)
    07-01 14:46:42.771: WARN/System.err(1725):     at android.view.ViewGroup.showContextMenuForChild(ViewGroup.java:459)
    07-01 14:46:42.771: WARN/System.err(1725):     at android.view.ViewGroup.showContextMenuForChild(ViewGroup.java:459)
    07-01 14:46:42.771: WARN/System.err(1725):     at android.view.ViewGroup.showContextMenuForChild(ViewGroup.java:459)
    07-01 14:46:42.771: WARN/System.err(1725):     at android.view.ViewGroup.showContextMenuForChild(ViewGroup.java:459)
    07-01 14:46:42.771: WARN/System.err(1725):     at android.view.View.showContextMenu(View.java:2444)
    07-01 14:46:42.771: WARN/System.err(1725):     at com.??.??.ui.cards.ViewActivity$3.onClick(ViewActivity.java:353)
    07-01 14:46:42.771: WARN/System.err(1725):     at android.view.View.performClick(View.java:2408)
    07-01 14:46:42.771: WARN/System.err(1725):     at android.view.View$PerformClick.run(View.java:8816)
    07-01 14:46:42.771: WARN/System.err(1725):     at android.os.Handler.handleCallback(Handler.java:587)
    07-01 14:46:42.771: WARN/System.err(1725):     at android.os.Handler.dispatchMessage(Handler.java:92)
    07-01 14:46:42.771: WARN/System.err(1725):     at android.os.Looper.loop(Looper.java:123)
    07-01 14:46:42.771: WARN/System.err(1725):     at android.app.ActivityThread.main(ActivityThread.java:4627)
    07-01 14:46:42.771: WARN/System.err(1725):     at java.lang.reflect.Method.invokeNative(Native Method)
    07-01 14:46:42.771: WARN/System.err(1725):     at java.lang.reflect.Method.invoke(Method.java:521)
    07-01 14:46:42.771: WARN/System.err(1725):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
    07-01 14:46:42.771: WARN/System.err(1725):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    07-01 14:46:42.771: WARN/System.err(1725):     at dalvik.system.NativeStart.main(Native Method)
    07-01 14:46:43.005: WARN/System.err(1725): android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRoot$W@44757528 is not valid; is your activity running?
    07-01 14:46:43.005: WARN/System.err(1725):     at android.view.ViewRoot.setView(ViewRoot.java:505)
    07-01 14:46:43.005: WARN/System.err(1725):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
    07-01 14:46:43.005: WARN/System.err(1725):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
    07-01 14:46:43.005: WARN/System.err(1725):     at android.view.Window$LocalWindowManager.addView(Window.java:424)
    07-01 14:46:43.005: WARN/System.err(1725):     at android.app.Dialog.show(Dialog.java:241)
    07-01 14:46:43.005: WARN/System.err(1725):     at com.android.internal.view.menu.MenuDialogHelper.show(MenuDialogHelper.java:86)
    07-01 14:46:43.005: WARN/System.err(1725):     at com.android.internal.view.menu.ContextMenuBuilder.show(ContextMenuBuilder.java:88)
    07-01 14:46:43.005: WARN/System.err(1725):     at com.android.internal.policy.impl.PhoneWindow$DecorView.showContextMenuForChild(PhoneWindow.java:1860)
    07-01 14:46:43.005: WARN/System.err(1725):     at android.view.ViewGroup.showContextMenuForChild(ViewGroup.java:459)
    07-01 14:46:43.005: WARN/System.err(1725):     at android.view.ViewGroup.showContextMenuForChild(ViewGroup.java:459)
    07-01 14:46:43.005: WARN/System.err(1725):     at android.view.ViewGroup.showContextMenuForChild(ViewGroup.java:459)
    07-01 14:46:43.005: WARN/System.err(1725):     at android.view.ViewGroup.showContextMenuForChild(ViewGroup.java:459)
    07-01 14:46:43.005: WARN/System.err(1725):     at android.view.ViewGroup.showContextMenuForChild(ViewGroup.java:459)
    07-01 14:46:43.005: WARN/System.err(1725):     at android.view.ViewGroup.showContextMenuForChild(ViewGroup.java:459)

If I catch the Exception, the button never opens up the contextmenu in this case, but other controls on the page continue to work.

If I minimize the application with the home screen, and then return, the application crashes with the following trace:

07-01 15:10:50.439: ERROR/AndroidRuntime(1931): FATAL EXCEPTION: main
07-01 15:10:50.439: ERROR/AndroidRuntime(1931): java.lang.NullPointerException
07-01 15:10:50.439: ERROR/AndroidRuntime(1931):     at android.view.WindowManagerImpl.removeViewLocked(WindowManagerImpl.java:239)
07-01 15:10:50.439: ERROR/AndroidRuntime(1931):     at android.view.WindowManagerImpl.closeAll(WindowManagerImpl.java:293)
07-01 15:10:50.439: ERROR/AndroidRuntime(1931):     at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3687)
07-01 15:10:50.439: ERROR/AndroidRuntime(1931):     at android.app.ActivityThread.access$2900(ActivityThread.java:125)
07-01 15:10:50.439: ERROR/AndroidRuntime(1931):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
07-01 15:10:50.439: ERROR/AndroidRuntime(1931):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-01 15:10:50.439: ERROR/AndroidRuntime(1931):     at android.os.Looper.loop(Looper.java:123)
07-01 15:10:50.439: ERROR/AndroidRuntime(1931):     at android.app.ActivityThread.main(ActivityThread.java:4627)
07-01 15:10:50.439: ERROR/AndroidRuntime(1931):     at java.lang.reflect.Method.invokeNative(Native Method)
07-01 15:10:50.439: ERROR/AndroidRuntime(1931):     at java.lang.reflect.Method.invoke(Method.java:521)
07-01 15:10:50.439: ERROR/AndroidRuntime(1931):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
07-01 15:10:50.439: ERROR/AndroidRuntime(1931):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
07-01 15:10:50.439: ERROR/AndroidRuntime(1931):     at dalvik.system.NativeStart.main(Native Method)

Here’s how I’m adding the ContextMenu:

b.setOnClickListener( new OnClickListener() {
            @Override
            public void onClick( View view ) {
                if (contextMenuOpen) return;// popup options
                contextMenuOpen = view.showContextMenu();

            }

I do not call registerForContextMenu with the button, but rather the main view itself. Is this incorrect?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:31:36+00:00Added an answer on May 23, 2026 at 11:31 am

    You are holding on to a reference to a Context (either explicitly, or by creating a Dialog or Toast or some other dependent item) that has been destroyed (typically because you are using the onCreateDialog or you passed the Activity to some other process that didn’t get destroyed when the Activity was destroyed).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an issue related to a Java application running under a (rather old)
We have an issue on our page whereby the first time a button posts
I have a weird issue. I receive the following error that causes a force-close:
Issue:- I am developing a application which needs a new acceleration datum every 5
i have a input tag which is non editable, but some times i need
I have a routing issue which I can't seem to get my head around.
I have subclassed NSWindow in a NSDocument application in order to receive keyDown events.
I have an issue that is driving me a bit nuts: Using a UserProfileManager
We have an issue using the PEAR libraries on Windows from PHP . Pear
I have some issue with a Perl script. It modifies the content of a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.