android – 启用ActionBar的活动在什么时候启动onCreateOptionsMenu?

我知道菜单项将被设置为ActionBar中的动作图标.

我想知道这个onCreateOptionsMenu函数,它什么时候在活动生命周期中调用.

从我的测试,它甚至没有onResume

解决方法

文件说明如下:
public boolean onCreateOptionsMenu (Menu menu)

初始化活动标准选项菜单内容.您应该将菜单项放入菜单.这只是一次调用,第一次显示选项菜单.要在每次显示时更新菜单,请参阅onPrepareOptionsMenu(菜单).

这里进一步说明:http://developer.android.com/reference/android/app/Activity.html#onCreateOptionsMenu%28android.view.Menu%29

并引用CommonsWare提出的另一个相关问题:

The onCreate method is called first,and before it finishes onCreateOptionsMenu is called.

That will be true on devices and apps with an official Honeycomb-style action bar. If there is no action bar,onCreateOptionsMenu() should not get called until the user calls up the menu,typically by pressing the MENU button.

链接Android: When is onCreateOptionsMenu called during Activity lifecycle?

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...