Android错误:"SuperNotCalledException:Activity未调用super.OnCreate()"

19

未捕获的句柄: 线程主要由于未捕获的异常而退出 android.app.SuperNotCalledException:Activity没有调用super.OnCreate()

我的代码是:

  public void onCreate(Bundle savedInstanceState) {
        boolean isEnabled = Settings.System.getInt(this.getApplicationContext().getContentResolver(),Settings.System.AIRPLANE_MODE_ON, 0) == 1;


                Settings.System.putInt(this.getApplicationContext().getContentResolver(),Settings.System.AIRPLANE_MODE_ON, isEnabled ? 0 : 1);

                // Post an intent to reload
                Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
                //intent.putExtra("state",! isEnabled);//Call ON
                try {
                    Thread.sleep(15000);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                intent.putExtra("state", isEnabled);
                                                                                           this.getApplicationContext().sendBroadcast(intent);


}
2个回答

33

添加 super.onCreate(savedInstanceState);

 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
        boolean isEnabled = Settings.System.getInt(this.getApplicationContext().getContentResolver(),Settings.System.AIRPLANE_MODE_ON, 0) == 1;
...
...
...

6

在对应的activity清单文件中添加以下代码

  android:screenOrientation="fullSensor"

这个问题发生在使用8.0版本且同时包含全屏Activity和对话框Activity的情况下。


1
在Android 8.0上也遇到了同样的问题。将screenOrientation设置为fullSensor即可解决。(由于某种原因,它无法在“portrait”模式下工作)。 - MW.
1
是的,fullSesor可以工作,但方向不会保持为竖屏,我想强制它保持为竖屏。你能帮忙吗?@Manuel - Asad Ali Choudhry

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接