android-notes / Cockroach

降低Android非必要crash
MIT License
3.25k stars 448 forks source link

我跳转到SecondActivity的时候,让其在oncreate发生异常后,App就黑屏了 #9

Closed Foreverpassenger closed 7 years ago

Foreverpassenger commented 7 years ago

MainActivity:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent( MainActivity.this, SecondActivity.class);
            startActivity(intent);
        }
    });
}

SecondActivity:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_second);
    String ing = null;
    Log.d("logggg", ing.length() + "");
    Button button = (Button) findViewById(R.id.btn);
    button.setText("hellosdfsfa");
}

这个黑屏是由于什么原因导致的呢,请教下

android-notes commented 7 years ago

因为activity没初始化结束所以导致了生命周期不完整,所以就出现了问题,Cockroach适合于由于服务端返回数据问题导致的crash,以及listview等这种延时加载view的控件,以及点击控件时导致的crash