title: How to prevent a notification to re-launch an Activity
body: <p>I have the following piece of code:</p>
  
  <pre><code>public void notify(int notificationId, int iconId, String message, Class&lt;?&gt; returnTo, boolean onGoing, boolean showTime, boolean autoCancel)
  {
      Intent intent = new Intent(mContext, returnTo);
      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
  
      TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
      stackBuilder.addParentStack(returnTo);
      stackBuilder.addNextIntent(intent);
  
      PendingIntent pending = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
  
      mNotificationBuilder.setContentTitle("Notification")
                          .setContentText(message)
                          .setSmallIcon(iconId)
                          .setContentIntent(pending)
                          .setAutoCancel(autoCancel);
  
      if (!showTime)
      {
          mNotificationBuilder.setWhen(0);
      }
  
      Notification notification = mNotificationBuilder.build();
  
      if (onGoing)
      {
          notification.flags |= Notification.FLAG_ONGOING_EVENT;
      }
  
      mNotificationManager.notify(NOTIFICATION_TAG, notificationId, notification);
  }
  </code></pre>
  
  <p>Which works perfectly to create a notification.</p>
  
  <p>However, the Activity that called this function (i.e. the <code>Class&lt;?&gt; returnTo</code> parameter) is started for a second time, instead of returning to the initial instance, when the notification is pressed.</p>
  
  <p>To try to circumvent this, I've added the flags <code>Intent.FLAG_ACTIVITY_CLEAR_TOP</code> &amp; <code>Intent.FLAG_ACTIVITY_SINGLE_TOP</code> to the Intent I create at the top of the function. Sadly, this didn't work, so I tried something else.</p>
  
  <p>I added <code>android:launchMode="singleTop"</code> to the Activity that is calling this code, to see if that would help. But sadly, this didn't work either.</p>
  
  <p>I've tried finding anything on Google, but all that comes up with are the flags (which, as mentioned, I've already tried) and the launchMode (as mentioned, also tried).</p>
  
  <p>So, are there any other flags, settings, etc. that I can try?</p>
  
  <h2>Edit:</h2>
  
  <p>There seems to be a bit of text on <code>android:launchMode="singleTop"</code> over on the Android Developers site (<a href="http://developer.android.com/guide/topics/manifest/activity-element.html#lmode" rel="nofollow">link</a>).</p>
  
  <p>This states:</p>
  
  <p><code>In other circumstances — for example, if an existing instance of the "singleTop" activity is in the target task, but not at the top of the stack, or if it's at the top of a stack, but not in the target task — a new instance would be created and pushed on the stack.</code></p>
  
  <p>Could it be possible that there is an issue with using <code>TaskStackBuilder</code> to get my <code>PendingIntent</code>, with regards to <code>or if it's at the top of a stack, but not in the target task</code>?</p>