title: android notification always relaunches activity
body: <p>First time poster here, please excuse my lengthy post - I want to provide all the necessary info.</p>
  
  <p>I am trying to achieve the coveted resume from clicking on notification functionality, but I am having some difficulties.  First off, details(code below):</p>
  
  <ol>
  <li><p>Project Properties</p>
  
  <pre><code>Android Developer Tools Build: v21.1.0-569685
  Project Build Target : 4.2.2
  Platofrm : 4.2.2
  API Level : 17
  SDK Target : 17
  SDK min : 14
  
  Android Device Chooser : Android Device : Nexus 4 
  </code></pre></li>
  <li><em>MyApp</em> launches <em>MyAppService</em> via startService</li>
  <li><em>MyAppService</em>'s onStartCommand function uses NotificationCompat.Builder object to create a bar in the pull down notification.</li>
  </ol>
  
  <p>The behavior I am trying to achieve :</p>
  
  <ol>
  <li>Launch an app with a notification bar entry(e.g. Mail)</li>
  <li>Start MyApp(this will also start MyAppService)</li>
  <li>Pull down the notification bar and select MyAppService(yes, MyApp is currently on screen</li>
  <li>Notification bar should just roll up w/o doing anything</li>
  </ol>
  
  <p>What I am noticing is that MyApp will minimize out, and a new instance of MyApp will maximize(similar transition to when the app is being launched).  I expect this behavior when I select on MyAppService when I have Mail app on top(Mail app to minimize and for MyApp to maximize).</p>
  
  <p>There have been many code snippets and suggestions but I can't seem to get it to work; so here are the contents of my files :</p>
  
  <p>AndroidManifest.xml</p>
  
  <pre><code>&lt;application
      android:allowBackup="true"
      android:icon="@drawable/eyeview"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
  
      &lt;activity
          android:name="com.example.MyApp.MainActivity"
          android:label="@string/app_name"
          android:launchMode="singleTop"
          &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;service
          android:name=".service.MyAppService"
          android:label="MyAppService"&gt;
      &lt;/service&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p>MyApp/MainActivity.java</p>
  
  <pre><code>public static Intent serviceIntent;
  public static Messenger clientMessenger;
  
  @Override
  protected void onCreate(Bundle savedInstanceState)
  {
      super.onCreate(savedInstance);
  
      if (getIntent().getFlags() &amp; Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
      {
          finish();
          return;
      }
  
      setContentView(R.layout.activity_main);
  
      ...
      [stuff specific to app, like setting up Fragments]
      ...
  
      MainActivity.serviceIntent = new Intent(this, MyAppService.class);
      MainActivity.serviceIntent.putExtra("clientMessenger", clientMessenger);
      startService(MainActivity.serviceIntent);
  }
  </code></pre>
  
  <p>MyAppService.java</p>
  
  <pre><code>@Override
  private int onStartCommand(Intent intent, int flags, int startId)
  {
      NotificationCompat.Builder ncB = new NotificationCompat.Builder(getApplicationContext())
          .setSmallIcon(R.drawable.icon_app)
          .setContentTitle("MyAppService")
          .setSmallIcon(R.drawable.app);
  
      ncB.setContentText("Click to start MyApp");
  
      Intent nIntent = new Intent(getApplicationContext(), MainActivity.class);
      nIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
      nIntent.setAction(Intent.ACTION_MAIN);
  
      TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext());
      stackBuilder.addNextIntent(nIntent);
      PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
  
      notificationBuilder.setContentIntent(resultPendingIntent);
      NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  
      int nId = 1;
      Notification notification = ncB.build();
      notification.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
  
      notificationManager.notify(nId, notification); 
  
      sendMessengerToClient(intent);
  
      startForeground(nId, ncB.build());
  
      return Service.START_NOT_STICKY;
  }
  </code></pre>
  
  <p>I hope I included all the enough information - I've been tweaking the code I got from SO just to see if this would work - in EVERY case, the topmost application minimizes out to black screen, and MyApp would maximize and MainActivity.java's onCreate function gets called.  </p>
  
  <p>I just want the notification pulldown to just scroll up if MyApp is already topmost.</p>
  
  <p>Thanks in advance!</p>