title: Clear Intent flags from an activity so that it resumes its original launch behavior
body: <p>My application has an activity defined as launchMode="singleTop" that serves as the root activity.</p>
  
  <pre><code>&lt;activity 
      android:name="com.package.LauncherActivity"
      android:launchMode="singleTop" 
      &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;
  </code></pre>
  
  <p>The application creates notifications that, when clicked, "restarts" this root activity using a PendingIntent containing an Intent with the flag Intent.FLAG_ACTIVITY_CLEAR_TOP. </p>
  
  <pre><code>Intent newIntent = new Intent(context, LauncherActivity.class);
  newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  
  PendingIntent pi = PendingIntent.getActivity(
      context, 
      (int)System.currentTimeMillis(), 
      newIntent, 
      PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
  </code></pre>
  
  <p>The idea is that, wherever the person is currently in the app, when they click on the notification it will clear the activity stack and start "from scratch" at this root activity.</p>
  
  <p>This all works properly and as expected.  I always have just the one task, and it correctly clears the stack when the notification's PendingIntent is executed.</p>
  
  <p>My problem occurs following one of these notification "restarts".  If the activity is then placed in the background and then re-launched using one of the various launchers(Recent Apps, Settings->Apps(see Update below, not exactly), etc.), the Intent used by the notification is used to start the activity <strong>including the Intent.FLAG_ACTIVITY_CLEAR_TOP</strong>.</p>
  
  <p><strong>UPDATE:</strong> Actually, my problem only applies to attempting to bring the app to the foreground using the "Recent Apps" launcher.  If I use the Settings->App launcher, it launches the app completely from scratch.  Still it's not "resuming" the app, as it did before I overwrote the default launch intent.  Also note that the app DOES resume as expected if I use the longpress-Home resume.  <strong>What's so different about the "Recent Apps" Launcher that makes it keep re-using that intent?</strong></p>
  
  <p>So at this point, every time they resume the app via a launcher it "clears top" and starts back at the beginning rather than simply resuming the app as it does before the notification's intent was used.  This happens because it's the same instance of the activity, and that activity continues to launch using the intent with which it was launched.  In this case, that means it has the FLAG_ACTIVITY_CLEAR_TOP flag every time.</p>
  
  <p><a href="https://groups.google.com/forum/#!topic/android-developers/vrLdM5mKeoY" rel="nofollow">This post</a> pretty much hit's the nail on the head, but my particular problem is not resolved.  In this post they address how to properly ignore(or use) the Extras in the Bundle of this re-used intent.  But I cannot figure out a way to clear the <em>flags</em> on that intent so that it stops launching using the CLEAR_TOP flag.</p>
  
  <p>I only want it to launch using the CLEAR_TOP flag one time, when the notification is pressed.  I want subsequent launches of the app to perform the same way as it did before the notification was pressed, which simply resumed the app/activity stack wherever the user was(rather than starting from scratch every time).</p>
  
  <p>I understand why the activity is re-using the intent.  I just need to find a way to either stop it from doing that, or somehow clear the CLEAR_TOP flag from that intent so that it goes back to working as it did before the PendingIntent restarted the activity with the FLAG_ACTIVITY_CLEAR_TOP flag.</p>
  
  <p>Thanks in advance for any help.</p>