title: Android Multiple Notifications and with multiple intents
body: <p>I have a fairly simple app that takes the input from a user and then sets it as a notification. The user can create as many notifications as he/she likes. I want the user to click the notification and get taken to a new activity called <code>ResultActivity</code>. <code>ResultActivity</code> in turn reads in the <code>putExtras</code> from the notifications intent and shows it to the user. The code below allows me to do almost everything I wanted, except anytime a notification is pressed, I receive the <code>putExtra</code> of the last created notification.</p>
  
  <pre><code>Intent notificationIntent = new Intent(ctx, MainActivity.class);
  PendingIntent contentIntent = PendingIntent.getActivity(ctx, i,notificationIntent,PendingIntent.FLAG_CANCEL_CURRENT);
  
  NotificationManager nm = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
  
  Resources res = ctx.getResources();
  NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx);
  builder.setContentIntent(contentIntent)
      .setSmallIcon(R.drawable.ic_launcher)
      .setLargeIcon(BitmapFactory.decodeResource(res,R.drawable.ic_launcher))
      .setTicker("Remember to " + text.getText())
      .setWhen(System.currentTimeMillis()).setAutoCancel(true)
      .setContentTitle(text.getText());
  
  // Creates an explicit intent for an Activity in your app
  Intent resultIntent = new Intent(this, ResultActivity.class);
  String pass = text.getText().toString();
  
  resultIntent.putExtra("title", pass);
  resultIntent.putExtra("uid", i);
  
  TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
  // Adds the back stack for the Intent (but not the Intent itself)
  stackBuilder.addParentStack(ResultActivity.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);
  
  new Uri.Builder().scheme("data").appendQueryParameter("text", "my text").build();
  builder.setContentIntent(resultPendingIntent);
  
  Notification n = builder.build();
  n.flags = Notification.FLAG_NO_CLEAR;
  nm.notify(i++, n);
  text.setText(null);
  </code></pre>
  
  <ol>
  <li><p>Open the application</p></li>
  <li><p>Type in "One"</p></li>
  <li><p>Hit ok</p></li>
  <li><p>Notification is sent</p></li>
  <li><p>Open the application</p></li>
  <li><p>Type in "Two"</p></li>
  <li><p>Hit ok</p></li>
  <li><p>Notification is sent</p></li>
  </ol>
  
  <p>Now you have two notifications. One that says "One" and one that says "Two". If you click on the notification "Two" it takes you to a screen that says "Two". Perfect!</p>
  
  <p>If you click on the notification "One" it takes you to a screen that says "Two". BROKEN!</p>
  
  <h2>ResultActivity.java</h2>
  
  <pre><code>public class ResultActivity extends Activity {
      String title = null;
      TextView text;
  
      int i=0;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity);
          text = (TextView) findViewById(R.id.textView1);
  
  
  
          title = getIntent().getStringExtra("title");
           i = getIntent().getIntExtra("uid", 0);
  
  
          text.setText(title);
  
      }
  </code></pre>