5
當屏幕旋轉時... Toast打印什麼都沒有!onSaveInstanceState不起作用
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
String a = savedInstanceState.getString("hello");
Toast.makeText(MainActivity.this, a, Toast.LENGTH_SHORT).show();
}
@Override
public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
super.onSaveInstanceState(outState, outPersistentState);
String a = "WTF";
outState.putString("hello",a);
}
}
我宣佈一切都很好,,哪裏是在這個簡單的代碼中的無賴!?