Android 要求所有 Activity 子类从其生命周期方法中调用超级方法。如果未调用 super 方法,则会引发异常。为什么Android会使用RuntimeException机制来强制调用super方法。为什么它不使用“模板”设计模式,以便超级方法在子方法之前自动执行。例如 onDestroy() 可以按如下方式处理:-
Class Activity{
public void onDestroyFrmwork()
{
//do whatever the super onDestroy() method has to do
onDestroy();//this will invoke the subclass method.
}
public void onDestroy()
{
//empty. will get overridden by subclasses.
}
}