title: Unexpected Back Stack Behavior
body: <p>I have a notification that launches an Activity (C) for which I build a back stack to adhere to the Android guidelines, the back stack:</p>
  
  <pre><code>C
  B
  A
  </code></pre>
  
  <p>The user clicks the notification, it opens C, then if they press back it goes to B, then to A, then to the home screen.  This works as expected.</p>
  
  <p>If the user clicks the notification (opening C), then presses the home button to go to the home screen, then launches the app from the home screen, it opens A, not C as I expect and want.  If they then press back (from A) it goes to C, then B, then A.  So, when they launch the app from the home screen in this situation, it's creating a new Activity A and putting it on top of the existing stack instead of opening the top of the existing stack (C), so the stack would look like:</p>
  
  <pre><code>A
  C
  B
  A
  </code></pre>
  
  <p>My code creating the back stack and launch intent for the notification:</p>
  
  <pre><code>/* Build the back stack for navigation */
  TaskStackBuilder stackBuilder = TaskStackBuilder.create( this );
  /* Pairing List */
  Intent intent = new Intent( this, A.class );
  intent.setFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP );
  stackBuilder.addNextIntent( intent );
  /* Pairing */
  intent = new Intent( this, B.class );
  intent.putExtra( "id", briefing.getLeg().getDay().getPairing().getId() );
  stackBuilder.addNextIntent( intent );
  
  /* Create a launch intent and notification */
  intent = new Intent( this, C.class );
  intent.putExtra( "date", briefing.getLeg().getDay().getDate() );
  intent.putExtra( "id", briefing.getLeg().getId() );
  intent.putExtra( "briefing", true );
  
  stackBuilder.addNextIntent( intent );
  pIntent = stackBuilder.getPendingIntent( 0, PendingIntent.FLAG_ONE_SHOT );
  </code></pre>
  
  <p>Activity declarations in my Manifest:</p>
  
  <pre><code>&lt;activity android:name=".C" /&gt;
  &lt;activity
      android:name=".A"
  &gt;
      &lt;intent-filter&gt;
          &lt;action android:name="android.intent.action.MAIN" /&gt;
          &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
      &lt;/intent-filter&gt;
  &lt;/activity&gt;
  &lt;activity android:name=".B" /&gt;
  </code></pre>
  
  <p>I think it's a problem with the flags I'm setting on the intents, but I'm not sure what I need to change.  Any ideas?</p>