How did Android implement the checks for SuperNotCalledException?

白昼怎懂夜的黑 提交于 2019-12-05 19:27:30

It looks like they clear a flag in the super methods and check that it was set:

final void performStart() {
    mCalled = false;
    mInstrumentation.callActivityOnStart(this);
    if (!mCalled) {
        throw new SuperNotCalledException(
            "Activity " + mComponent.toShortString() +
            " did not call through to super.onStart()");
    }
}

As a side-note android just announced a new annotation, @CallSuper that drops you a warning whenever the super is not called for the @CallSuper annotated method when it gets overidden.

More details:

http://tools.android.com/tech-docs/support-annotations

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