In my project i am trying to open the optionsMenu programmatically without a click on the menu key from the user. I have tried openOptionsMenu() but it gives me an error like this android.view.WindowManager$BadTokenException: Unable to add window -- .. why it is... what is the solution for this...
08-13 14:53:02.687: E/AndroidRuntime(1213): FATAL EXCEPTION: main 08-13 14:53:02.687: E/AndroidRuntime(1213): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.veytila.candideye/com.veytila.candideye.MainActivity}: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
I believe you are doing this in Oncreate or onResume. You will have to call this api only after the window of the activity has been initialized. One way is to post a delayed runnable in your onresume on to ui thread.