当我的线程启动时,我将 an 设置AtomicBoolean
为 true。最后,我在关联的处理程序中将其重置为 false。
当我在线程结束之前更改屏幕方向时:
- onSaveInstanceState() 打印此布尔为 TRUE
- onPause() 也打印 TRUE。-> 逻辑
线程结束,我再次改变方向:
- 我的 Log.e "Bool" 打印 FALSE -> OK
- onSaveInstanceState() 打印 TRUE -> 问题
- onPause() 打印 TRUE -> 问题
- onCreate() 打印 TRUE -> 问题
创建():
if (savedInstanceState != null) {
boolLocThread.set(savedInstanceState.getBoolean("boolLocThread"));
Log.i("APP", "load LOC: " + boolLocThread.get());
if (boolLocThread.get()) {
Log.i("APP", "show progressDialog again");
progressDialog = ProgressDialog.show(App.this, "", "Loading...", true);
}
}
处理程序:
Handler handlerLoc = new Handler() {
@Override
public void handleMessage(Message msg) {
Log.i("APP", "Handler received (LOC)");
Log.i("APP", "Suppress progressDialog (LOC)");
progressDialog.dismiss();
boolLocThread.set(false);
Log.e("APP", "Bool: " + String.valueOf(boolLocThread.get()));
}
};
OnSaveInstanceState:
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean("boolLocThread", boolLocThread.get());
Log.i("APP", "save LOC: " + boolLocThread.get());
}
在 OnStop 方法中,我将布尔值设置为 false,在 OnPause 方法中,如果它存在,我将关闭我的 progressDialog。如果我在结束前不转动屏幕,bool 被重置为 FALSE,没有问题。我怎样才能正确重置我的布尔值?谢谢