app关闭并重新打开仍然保存的实例为空?为什么

时间:2018-02-19 05:15:41

标签: android

我尝试再次打开应用saveinstance仍然为空 我的代码是正确的?谢谢你的回答

public class MainActivity extends AppCompatActivity {

TextView cc;

@Override

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
      cc=(TextView) findViewById(R.id.test);

    Toast.makeText(this,"Oncreate",Toast.LENGTH_LONG).show();



    if (savedInstanceState != null) {

       cc.setText( "=++++++++++++++");
        Toast.makeText(getApplicationContext(),"not null",Toast.LENGTH_SHORT);
    }else{

        Toast.makeText(getApplicationContext(),"OnCreate",Toast.LENGTH_SHORT);
        cc.setText("kkkkkkkkkk");




    }
}



@Override
public void onSaveInstanceState(Bundle out){

    Toast.makeText(this,"onSavedInstance",Toast.LENGTH_SHORT).show();
    out.putString("checking", "checking");

    super.onSaveInstanceState(out);

}

0 个答案:

没有答案