新人求解答 为什么Activity里的每一个方法都要调用父类的方法一次 如题.如super.oncreate();super.onstart(); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 因为父类的实现在子类方法中执行是需要的,这个是由AndroidFramework实现决定的。 不调用在语法上是可行的,但在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()"); } } 至于为什么这样规定,偶也不清楚..... 如何实现选择文件夹对话框并获取路径 android中常见控件EditText,TextView,Button,menu简单用法实例 关于byte转换为string类型的问题。 android的textView中添加链接的时候,若链接为email,程序直接挂掉,求解决 如何在listview中为每行添加按钮? 求大神帮我添加一个后台运行的代码吧 关于系统横竖屏 电脑VS手机 50RMB求SAX解析XML网站代码问题的解答 android Android Eclipse 的XML解析问题,求大神指教 CSDN未解问题之一 请教,用Eclipse调试Android程序时,总是启动新的AVD
来看一下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()");
}
}
至于为什么这样规定,偶也不清楚.....