onCreateOptionsMenu() calling super

前端 未结 2 1889
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-23 20:21

I\'m creating application with OptionsMenu. I found few examples with it, but everyone is using different place where to call super.onCreateOptionMenu

2条回答
  •  青春惊慌失措
    2020-12-23 21:01

    The source for onCreateOptionsMenu() is as follows:

    public boolean onCreateOptionsMenu(Menu menu) {
        if (mParent != null) {
            return mParent.onCreateOptionsMenu(menu);
        }
        return true;
    }
    

    Where mParent is the parent Activity of the current Activity. If your Activity extends android.app.Activity then can just return true at the end and not worry about calling the super, as the default implementation will attempt to show a menu based on the parent Activity, which you probably don't want.

提交回复
热议问题