//这是我的主要活动
@Override
protected void onResume() {
super.onResume();
System.out.println("onResume()");
// getting the value form some other class(checking one the activity is started)
try {
bundle = getIntent().getExtras();
myFlag = bundle.getBoolean("KEY");
} catch (Exception e) {
System.out.println(".......Error.......");
}
}
我正在使myFlag = true,我的问题是当我改变方向时(即重新启动活动),我想myFlag = false,但它仍然是真的...意味着我想要在方向上清除束值更改。 我在onDestroy()方法中尝试过bundle.clear()和bundle.remove(“KEY”),但没有用。
我已经用过了..
@Override
protected void onDestroy() {
super.onDestroy();
System.out.println("onDestroy()");
if(bundle!=null) {
bundle.clear();
// i also use the below statement
// bundle.remove("KEY");
}
}
答案 0 :(得分:2)
看到这个,你可以有个主意
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
if (savedInstanceState.getBoolean("activity_restarting")) {
// activity is restarting... Don't check mFlag..for that do something something here :)
}
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean("activity_restarting", true);
}
我希望你现在可以处理