我从 MainActivity 扩展了一个“登录”类。
MainActivity 看起来像这样:
public class MainActivity extends FragmentActivity {
/** Called when the activity is first created. */
private static String TAG = "MainActivity";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
Intent login_activity = new Intent(this, Login.class);
startActivity(login_activity);
Log.d(TAG,"Login created");
}
}
在 login.class 我只是调用布局:
public class Login extends MainActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
//super.onCreate(savedInstanceState);
setContentView(R.layout.login);
}
}
你可以看到,我在登录类中注释掉了“super.oncreate”。在这里再次调用 MainActivity oncreate 是没有意义的。但是这个被淘汰的 super.oncreate 我会得到一些例外:
12-31 11:37:47.688: E/AndroidRuntime(4206): FATAL EXCEPTION: main
12-31 11:37:47.688: E/AndroidRuntime(4206): android.app.SuperNotCalledException: Activity {de.svennergr.htn/de.svennergr.htn.Login} did not call through to super.onCreate()
12-31 11:37:47.688: E/AndroidRuntime(4206): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2146)
12-31 11:37:47.688: E/AndroidRuntime(4206): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
12-31 11:37:47.688: E/AndroidRuntime(4206): at android.app.ActivityThread.access$600(ActivityThread.java:141)
12-31 11:37:47.688: E/AndroidRuntime(4206): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
12-31 11:37:47.688: E/AndroidRuntime(4206): at android.os.Handler.dispatchMessage(Handler.java:99)
12-31 11:37:47.688: E/AndroidRuntime(4206): at android.os.Looper.loop(Looper.java:137)
12-31 11:37:47.688: E/AndroidRuntime(4206): at android.app.ActivityThread.main(ActivityThread.java:5039)
12-31 11:37:47.688: E/AndroidRuntime(4206): at java.lang.reflect.Method.invokeNative(Native Method)
12-31 11:37:47.688: E/AndroidRuntime(4206): at java.lang.reflect.Method.invoke(Method.java:511)
12-31 11:37:47.688: E/AndroidRuntime(4206): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-31 11:37:47.688: E/AndroidRuntime(4206): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-31 11:37:47.688: E/AndroidRuntime(4206): at dalvik.system.NativeStart.main(Native Method)
当我不评论 super.oncreate 时,我会得到一个不停止的循环,创建许多“登录”对象/活动。
我该如何解决这个问题?