title: Notification created by IntentService uses always a wrong Intent
body: <h2>Problem</h2>
  
  <p>When the user presses <kbd>Send "Button 1"</kbd>(scroll down to see the construction of the app) a new <a href="http://developer.android.com/reference/android/app/Notification.html"><code>Notification</code></a> is created from the <code>RefreshService</code>. If the user presses this notification a <code>MainActivity</code> instance gets started and receives a <a href="http://docs.oracle.com/javase/6/docs/api/java/lang/String.html"><code>String</code></a> with the value <code>Button 1</code> over the <a href="http://developer.android.com/reference/android/content/Intent.html"><code>Intent</code></a>.</p>
  
  <p>This value gets displayed.</p>
  
  <p>When the user presses now the <kbd>Send "Button 2"</kbd> a new <a href="http://developer.android.com/reference/android/app/Notification.html"><code>Notification</code></a> is created from the <code>RefreshService</code>. If the user presses this notification a <code>MainActivity</code> instance gets started and receives a <a href="http://docs.oracle.com/javase/6/docs/api/java/lang/String.html"><code>String</code></a> <strong>ALSO</strong> with the value <code>Button 1</code> over the <a href="http://developer.android.com/reference/android/content/Intent.html"><code>Intent</code></a>.</p>
  
  <p>So as you can guess, normally there should be the value <code>Button 2</code>. </p>
  
  <p>When the first Button the user pressed was <kbd>Send "Button 2"</kbd> then there would allways <code>Button 2</code> be sent.</p>
  
  <p>The only sollution to get the value of the second button is to restart the phone and pressing the second button first. Even force close doesn't work.</p>
  
  <p>I know that I also can change the UI in another way. But I need this approach in a app where I need to restart the 'MainActivity' with another <a href="http://developer.android.com/reference/android/content/Intent.html"><code>Intent</code></a> so the approach should be the same.</p>
  
  <h2>Construction</h2>
  
  <ul>
  <li><p>A <a href="http://developer.android.com/reference/android/app/Activity.html"><code>Activity</code></a> called <code>MainActivity</code></p></li>
  <li><p>A <a href="http://developer.android.com/reference/android/app/IntentService.html"><code>IntentService</code></a> called <code>RefreshService</code></p></li>
  </ul>
  
  <p><strong><em>MainActivity</em></strong></p>
  
  <pre><code>public class MainActivity extends Activity implements View.OnClickListener {
      public static final String RECEIVED = "received";
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          ((TextView)findViewById(R.id.textView_received)).setText(getIntent().getStringExtra(RECEIVED));
  
          findViewById(R.id.button_1).setOnClickListener(this);
          findViewById(R.id.button_2).setOnClickListener(this);
      }
  
      @Override
      public void onClick(View v) {
          Intent intent = new Intent(this, RefreshService.class);
  
          if(v.getId() == R.id.button_1){
              intent.putExtra(RECEIVED, "Button 1");
              Toast.makeText(this,"Sent \"Button 1\"",Toast.LENGTH_LONG).show();
          }
          else if(v.getId() == R.id.button_2){
              intent.putExtra(RECEIVED, "Button 2");
              Toast.makeText(this,"Sent \"Button 2\"",Toast.LENGTH_LONG).show();
          }
  
          startService(intent);
      }
  }
  </code></pre>
  
  <p><strong><em>RefreshService</em></strong></p>
  
  <pre><code>public class RefreshService extends IntentService {
      public RefreshService() {
          super("RefreshService");
      }
  
      @Override
      protected void onHandleIntent(Intent intent) {
          String received = intent.getStringExtra(MainActivity.RECEIVED);
  
          Intent notificationIntent = new Intent(this, MainActivity.class);
          notificationIntent.putExtra(MainActivity.RECEIVED, received);
          notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  
          PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
  
          NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setContentTitle("IntentServiceRefresh").setContentText(received).setSmallIcon(R.drawable.ic_notification_small).setContentIntent(pendingIntent);
          Notification notification = builder.build();
  
          // Hide the notification after it's selected
          notification.flags |= Notification.FLAG_AUTO_CANCEL;
  
          NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
          notificationManager.notify(0, notification);
      }
  }
  </code></pre>
  
  <p><strong><em>App Layout</em></strong><br>
  <img src="https://i.stack.imgur.com/pYtcl.png" alt="App Layout"> </p>