title: Android: when coming from notification, activities are added on top of already open activities and memory increases
body: <p>Android: when coming from notification, activities are added on top of already open activities and memory increases. 
  How to clear all the previous activities or even kill the app when notification is tapped?</p>
  
  <p>Here is how I build my notifications:</p>
  
  <pre><code>    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)//
              .setContentTitle(notificationTitle)//
              .setContentText(notificationText)//
              .setSmallIcon(R.drawable.app_icon_transparent)//
              .setAutoCancel(true)//
              .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.asd));//
  
      // Creates an explicit intent for an Activity in your app
      Intent resultIntent = new Intent(context, StarterActivity.class);
      resultIntent.putExtra("comingFromNotification", true);
  
      // The stack builder object will contain an artificial back stack for
      // the
      // started Activity.
      // This ensures that navigating backward from the Activity leads out of
      // your application to the Home screen.
      TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
      // Adds the back stack for the Intent (but not the Intent itself)
      stackBuilder.addParentStack(StarterActivity.class);
      // Adds the Intent that starts the Activity to the top of the stack
      stackBuilder.addNextIntent(resultIntent);
      PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
      mBuilder.setContentIntent(resultPendingIntent);
      NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
      // mId allows you to update the notification later on.
  
      mNotificationManager.notify((int) now.getTimeInMillis(), mBuilder.build());
  </code></pre>
  
  <p>Now, when the user receives a notification and clicks it, StarterActivity is started. It initiates all the resources the app needs and then starts the main activity.</p>
  
  <p>If the app had been running up to this moment and had been taking up 50 mb of ram, now ram goes up to 65, which means the previous process is not killed and this one starts on top of it.</p>
  
  <p>Question is, how to kill the app if its running in the moment the user clicks the notification?</p>
  
  <p>EDIT: In some similar question I found this</p>
  
  <pre><code>notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP| Intent.FLAG_ACTIVITY_NEW_TASK);
  </code></pre>
  
  <p>will this help? What do these flags mean?</p>
  
  <p>EDIT2: Nope. those flags didnt help. The application  process that has some cached objects in memory still lives and the RAM goes up again.</p>