When my Thread starts, I set an AtomicBoolean
to true.
At the end, I reset it to false in the associated Handler.
When I change the screen orientation BEFORE the end of the Thread:
- onSaveInstanceState() prints that this bool is TRUE
- onPause() prints TRUE too. -> Logical
The thread ends, I change again the orientation:
- My Log.e "Bool" prints FALSE -> OK
- onSaveInstanceState() prints TRUE -> Problem
- onPause() prints TRUE -> Problem
- onCreate() prints TRUE -> Problem
OnCreate():
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:
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());
}
In the OnStop method I set my boolean to false and in the OnPause method I dismiss my progressDialog IF it exists. If I don't turn the screen before the end, the bool is reset to FALSE, and there is no problem. How could I reset correctly my boolean? Thanks