如题.如super.oncreate();super.onstart();

解决方案 »

  1.   

    因为父类的实现在子类方法中执行是需要的,这个是由AndroidFramework实现决定的。
      

  2.   

    不调用在语法上是可行的,但在android的activity中是会抛android.app.SuperNotCalledException这个异常的.
    来看一下activity的onStart和onCreate方法究竟做了些什么:
     protected void onCreate(Bundle savedInstanceState) {
            mVisibleFromClient = mWindow.getWindowStyle().getBoolean(
                    com.android.internal.R.styleable.Window_windowNoDisplay, true);
            mCalled = true;
        }
      protected void onStart() {
            mCalled = true;
        }
    主要是mCalled这个变量,在performStart方法中会判断这个mCalled的值,如果为false则抛异常:
      final void performStart() {
            mCalled = false;
            //这句话调用到了activity本身的onStart方法
            mInstrumentation.callActivityOnStart(this);
            if (!mCalled) {
                throw new SuperNotCalledException(
                    "Activity " + mComponent.toShortString() +
                    " did not call through to super.onStart()");
            }
        }
     至于为什么这样规定,偶也不清楚.....