0
我保存這個字符串與onSaveInstanceState()方法的onSaveInstanceState()方法的關鍵「消息」只是在onCreate()方法顯示一個toast它不工作。我究竟做錯了什麼 ?爲什麼數據保存在onSaveInstanceState()方法返回null
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initComponents();
onClickLogin();
if(savedInstanceState!=null){
String message = savedInstanceState.getString("message");
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
}
@Override
public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
super.onSaveInstanceState(outState, outPersistentState);
outState.putString("message", "This is my message to be reloaded");
}
我已經嘗試在下面的onSaveInstanceState()中切換2語句,但我得到了相同的結果。
@Override
public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
outState.putString("message", "This is my message to be reloaded");
super.onSaveInstanceState(outState, outPersistentState);
}
使用這個'public void onSaveInstanceState(Bundle outState){',這是一個騙局,我已經回答 –