lifecycle out of order, related to 'back key detected but Activity not ending
<p>This is related to the question at: </p>

<p><a href="http://stackoverflow.com/questions/10365349/back-key-detected-but-activity-not-ending">back key detected but Activity not ending</a></p>

<p>Basically, I have to hit BACK twice to exit my Activity (I'm calling it C)  There is a status method called sessionActive().  </p>

<p>If sessionActive() is FLASE and BACK is pressed Activity C should end.</p>

<p>I have included a call to finish() in the onKeyDown()/onBackPressed()</p>

<p>I have traced thru the onCreate(), onResume() etc methods and don't understand the sequence I see.  The below snippets from logcat show lifecycle methods seemingly happening out of order:</p>

<pre><code>C.onCreate() 
C.onStart() 
C.onResume() 
C.onKeyDown() sessionActive()==false, keyCode = BACK              
                      This is the 1st BACK press that should get us out but doesn't

C.finish() sessionActive is FALSE                                
                      Shouldn't this execute onStop()?

C.onPause() sessionActive is FALSE      &lt;- Why are these running?
C.onRestart() sessionActive is FALSE       
C.onStart() sessionActive is FALSE      
C.onResume() sessionActive is FALSE

C.onStop() sessionActive is FALSE       &lt;- These makes sense.
C.onDestroy() sessionActive is FALSE

C.onPause() sessionActive is FALSE      &lt;- Why didn't the previous onDestroy() stop us?

C.onResume() sessionActive is FALSE     &lt;- Confusing!!!

C.onKeyDown() sessionActive is FALSE, keyCode = BACK
                    This is 2nd BACK press that causes Activity C to exit.

C.finish() sessionActive is FALSE
C.onPause() sessionActive is FALSE      &lt;- Why is there is no onRestart here?

C.onStop() sessionActive is FALSE       &lt;- This is the sequence I expect.
C.onDestroy() sessionActive is FALSE
</code></pre>

<p>Is this normal?  If it is, I do not understand why the lifecycle is executing differently.</p>

<p>Can it be related to how Activity C is started:</p>

<pre><code>    Intent startActivity = new Intent();
    startActivity.setClass(this,C.class);
    startActivity.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    startActivity(startActivity);
</code></pre>

<p>Can it be related to the application being defined as android:launchMode="singleTask" ??</p>

<p>Are there any requirements about how the Activity launching C should be defined/started?  How about the Activity launching the Activity launching C?</p>
