在Activity
类中,Android 提供super()
must be called 的运行时执行。用于覆盖生命周期回调方法。如果您忘记这样做,它会抛出 SuperNotCalledException。
具体是如何在 Android 上实现的?如果可能,请指出实际的源代码实现。
最佳答案
看起来他们 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()");
}
}
关于android - Android 是如何实现对 SuperNotCalledException 的检查的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11867246/