In the Activity
class, Android provides runtime enforcement that super()
must be called for overridden lifecycle callback methods. If you forget do do so, it throws SuperNotCalledException.
Exactly how was this implemented specifically on Android? Please point me to the actual source implementation if possible.
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