我到目前为止试图将行openOptionsMenu();在onCreate(),onResume()和从onCreate()发送到runOnUIThread()的runnable中,没有运气 - 我得到一个例外:
11-16 10:14:57.499: E/AndroidRuntime(939): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
我如何确保执行openOptionsMenu();当活动正在运行时?
答案 0 :(得分:1)
试试这个。将以下方法添加到您的活动中,并从中调出openOptionsMenu()
,就像我在此处所示。
@Override
public void onWindowFocusChanged(boolean hasFocus) {
openOptionsMenu();
super.onWindowFocusChanged(hasFocus);
}