title: Android - Notifications PendingIntent goes to wrong Activity?
body: <p>I currently have a notification that displays in the notification bar and when the user clicks it it should bring them to the root Activity of my application.</p>
  
  <p>I have used android:finishOnTaskLaunch ="true" &amp; android:clearTaskOnLaunch="true" in my manifest to achieve this when the user presses the app icon from the apps screen or the home screen. The user is always taken to the root activity as expected.</p>
  
  <p>However when I use the following code from my notification the user gets taken to the last screen they were on rather than the root activity which is StartActivity.</p>
  
  <p>Does anyone know what I'm doing wrong? </p>
  
  <pre><code>   Intent notificationIntent = new Intent(this, StartActivity.class);
     contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
     notification.setLatestEventInfo(getApplicationContext(), getString(R.string.notification_app_name), notificationText, contentIntent);
     mNotificationManager.notify(1, notification);
  </code></pre>
  
  <p>Adding these flags helps however it still doesn't work after a restart:</p>
  
  <pre><code>notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  </code></pre>
  
  <p>When I restart my application I set a service running which pops up the notification and when I do this the notification reverts back to the old undesired behavior .</p>
  
  <p>SOLVED:</p>
  
  <p>Solved the issue by adding this flag to the contentIntent of my notification - Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED.</p>
  
  <p>Here is an link with some excellent information on the area <strong><a href="http://groups.google.com/group/android-developers/browse_thread/thread/da024bcaf4e1960f" rel="nofollow">Google dev group</a></strong></p>