可以参考Fragment.java,Activity.java等代码,以Fragment.java来说明, void performResume() { mCalled = false; onResume(); if (!mCalled) { throw new SuperNotCalledException("Fragment " + this + " did not call through to super.onResume()"); } } public void onResume() { mCalled = true; }
void performResume() { mCalled = false;
onResume();
if (!mCalled) {
throw new SuperNotCalledException("Fragment " + this
+ " did not call through to super.onResume()");
} } public void onResume() {
mCalled = true;
}
在调用onResume之前先设置变量mCalled 为false,然后调用onResume,而这个mCalled 是在父类(也就是当前调用onResume的类)的onResume中设置为true的,如果子类没有写super.onResume(),自然就不会置为true,然后就可以抛出异常了。
......
if (!r.activity.mCalled) {
throw new SuperNotCalledException(
"Activity " + r.intent.getComponent().toShortString() +
" did not call through to super.onPause()");
}
......
}如果对象的mCalled没有被置为true,就抛出SuperNotCalledException异常