title: Foreground Service being killed on Notification click
body: <p>In Android 4.4.2 clicking on my Foreground Service notification is killing my process.</p>
  
  <p>On older devices (Samsuing Tab 2 running 4.2.2), I can swipe away the Activity from Recent Tasks and still have my <code>Service</code> running fine in the background. Then when I click on the <code>Notification</code> my app <code>Activity</code> starts again quite happily.</p>
  
  <p>However, once I click the Notification on my Nexus 7 running 4.4.2 my process is killed (which up until the click is running happily in the background). The <code>PendingIntent</code> doesn't seem to fire at all, or at least, it doesn't hit the first line of the <code>BroadcastReceiver</code>:</p>
  
  <pre><code>05-21 16:17:38.939: I/ActivityManager(522): Killing 2268:com.test.student/u0a242 (adj 0): remove task
  </code></pre>
  
  <p>I've run through <a href="https://stackoverflow.com/a/14293528/726954">this</a> answer, and using the command <code>dumpsys activity proccesses</code> I've confirmed that my Service <em>is</em> running in the foreground correctly.</p>
  
  <p>So, what is it about clicking this Notification which is killing my process? </p>
  
  <p>Code involved in moving the Service to the Foreground follows:</p>
  
  <p>Service:</p>
  
  <pre><code>@Override
  public int onStartCommand(Intent intent, int flags, int startId) {
      Log.i("NativeWrappingService", "Starting Service...");
      startForeground(NotificationIcon.NOTIFICATION_STUDENT, NotificationManager.getStudentIcon(this).getNotification());    
      return super.onStartCommand(intent, flags, startId);
  }
  </code></pre>
  
  <p>NotificationIcon: (<code>getStudentIcon(this).getNotification()</code>)</p>
  
  <pre><code>public Notification getNotification() {
      Builder mBuilder = new Builder(mContext);
  
      if(mSmallIcon   != -1)      mBuilder.setSmallIcon(mSmallIcon);
      if(mLargeIcon   != null)    mBuilder.setLargeIcon(mLargeIcon);
      if(mTitle       != null)    mBuilder.setContentTitle(mTitle);
      if(mSubTitle    != null)    mBuilder.setContentText(mSubTitle);
      if(mSubTitleExtra != null)  mBuilder.setContentInfo(mSubTitleExtra);
  
      mBuilder.setOngoing(mOngoing);
      mBuilder.setAutoCancel(mAutoCancel);
      mBuilder.setContentIntent(getPendingIntent(mContext, mAction, mBundle, mActivity));
  
      return mBuilder.build();
  }
  
  private PendingIntent getPendingIntent(Context context, String action, Bundle extras, String activity) {
      Intent newIntent = new Intent(context, BroadcastToOrderedBroadcast.class);
      Bundle bundle;
      if(extras != null)  bundle = extras;
      else                bundle = new Bundle();
  
      if(activity != null &amp;&amp; !activity.equalsIgnoreCase("")) {
          BundleUtils.addActivityToBundle(bundle, activity);
      }
  
      BundleUtils.addActionToBundle(bundle, action);
  
      newIntent.putExtras(bundle);
  
      return PendingIntent.getBroadcast(NativeService.getInstance(), mNotificationID, newIntent, PendingIntent.FLAG_UPDATE_CURRENT);
  }
  </code></pre>