Why do we have to call super in Android sometimes?

后端 未结 6 1088
暗喜
暗喜 2020-11-29 21:05

Sometimes when I override methods, I get an exception the first time it\'s called like below:

05-31 21:32:04.266: E/AndroidRuntime(28471): android.support.v4         


        
6条回答
  •  天涯浪人
    2020-11-29 21:33

    The requirement is generally specified directly in the API documentation. For example, see android.widget.ListView.onFinishInflate:

    protected void onFinishInflate ()

    ...

    Even if the subclass overrides onFinishInflate, they should always be sure to call the super method, so that we get called.

    Unfortunately, my personal experience is that Android docs are uneven in quality. So, I suspect there are cases where the call is required but not documented as such.

提交回复
热议问题