Caused by: java.lang.IllegalStateException: Activity has been destroyed

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.afmoney.videodownload/com.afmoney.videodownload.views.launch.MainActivity}: java.lang.IllegalStateException: Activity has been destroyed

Caused by: java.lang.IllegalStateException: Activity has been destroyed

.........还有一堆

我出现这个错误的是在 activity 添件Fragment 然后show();

出现错误的原因

我的 baseactivity 

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        xContext = this ;
        ActivityManagerUtil.getInstance().addActivity(this);
        setContentView();
        initUI();
        EventBus.getDefault().register(this);
//        ImmersionBar.with(this).init();
        super.onCreate(savedInstanceState);
    }

先做了一堆事情在调 super.onCreate(savedInstanceState);

解决办法 :把 super.onCreate(savedInstanceState); 最先调用

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        xContext = this ;
        ActivityManagerUtil.getInstance().addActivity(this);
        setContentView();
        initUI();
        EventBus.getDefault().register(this);
//        ImmersionBar.with(this).init();
    }
扫描二维码关注公众号,回复: 5326710 查看本文章

完事......

猜你喜欢

转载自blog.csdn.net/u013171212/article/details/87930147