Android: reason for calling superclass?

試著忘記壹切 提交于 2019-12-12 12:07:04

问题


I'm looking at the Notepad tutorial from the Android developer's site. I have a question about overridden functions calling the super-class of activities. For example,

public class Notepadv3 extends ListActivity {
    ...

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    menu.add(0, INSERT_ID, 0, R.string.menu_insert);
    return true;
    }
}

What's the point of the super.onCreateOptionsMenu()? I looked at the developer's site and found this explanation:

Call super.onCreateOptionsMenu(menu) so the original menu items are created, then add new menu items with menu.add().

But what original menu items are there?

Similarly, what's the point of other super.(overridden_function), such as super.onCreateContextMenu?


回答1:


Activities have a number of operations they perform throughout their life cycle - some of these are house cleaning (garbage collection), UI stuff, etc.

As far as I know, super.onCreateContextMenu() doesn't have to be called, unlike methods like onCreate, onResume, etc.



来源:https://stackoverflow.com/questions/6968757/android-reason-for-calling-superclass

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!