標籤:
//activity銷毀之前調用,把狀態值儲存上
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putBoolean("isConflict", false);
outState.putBoolean(Constant.ACCOUNT_REMOVED, false);
super.onSaveInstanceState(outState);
}
然後再oncreate裡面判斷
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//如果activity銷毀之前儲存了。savedInstanceState 就不是null
if (savedInstanceState != null && savedInstanceState.getBoolean(Constant.ACCOUNT_REMOVED, false)) {
// 防止被移除後,沒點確定按鈕然後按了home鍵,長期在後台又進app導致的crash
// 三個fragment裡加的判斷同理
DemoHelper.getInstance().logout(true,null);
finish();
startActivity(new Intent(this, LoginActivity.class));
return;
} else if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false)) {
// 防止被T後,沒點確定按鈕然後按了home鍵,長期在後台又進app導致的crash
// 三個fragment裡加的判斷同理
finish();
startActivity(new Intent(this, LoginActivity.class));
return;
}
android onSaveInstanceState應用執行個體