0

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

Gray
  • 115,027
  • 24
  • 293
  • 354
Anduriel
  • 93
  • 2
  • 10
  • You are going to have to show some concise code examples. Otherwise we would be guessing. – Gray May 25 '12 at 13:09
  • So either `AtomicBoolean.set(false)` is not being called or `set(true)` is being called after the false. Have you determined which one is more likely? – Gray May 25 '12 at 13:10
  • So you change orientation which calls `OnCreate()` again right? THis is overwriting your `boolLocThread` value. I don't quite understand the point of your `savedInstanceState`. So your question is if you can detect the orientation change and only overwrite the `boolLocThread` value if it is not happening? – Gray May 25 '12 at 16:01
  • When the thread starts, I show a Dialog. So when I turn, I detroy the Dialog (to avoid crash because it's not longer recognized) and show a new one when the OnCreate() is called again. That is why I retain the boolean value, to know if the thread is running or not. – Anduriel May 25 '12 at 17:35

0 Answers0