title: How to cancel current activity during the creation of the same one?
body: <p>There is the following code:</p>
  
  <pre><code>    Intent i = new Intent(this, MessagesActivity.class);
      PendingIntent pi = PendingIntent.getActivity(this, 100, i, PendingIntent.FLAG_CANCEL_CURRENT);
      NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
  
      NotificationCompat.Builder nb = new NotificationCompat.Builder(this);
      nb.setContentText("There is a new message for you").setContentTitle("New message").setContentIntent(pi);
      nb.setWhen(System.currentTimeMillis()).setDefaults(Notification.DEFAULT_ALL);
      nb.setTicker("SomeText").setSmallIcon(android.R.drawable.ic_dialog_alert);
      manager.notify(100, nb.getNotification());
  </code></pre>
  
  <p>When user clicks by some notification created with this code the app should open MessagesActivity activity. It works. But if user is in MessagesActivity already this code executes a new copy of MessagesActivity. How can I fix it? Thanks in advance. </p>