title: Get intent extras if activity is running
body: <p>I'm struggling with this problem: I have some notifications and I want to pass intent extras to an activity, even if the application is already running.</p>
  
  <p>Some solutions I found here on S.O. didn't work for me, like adding:</p>
  
  <pre><code>android:launchMode="singleTop"
  </code></pre>
  
  <p>to the manifest, I'm also using this:</p>
  
  <pre><code>notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
  </code></pre>
  
  <p>like someone suggested.</p>
  
  <p>My code is this:</p>
  
  <pre><code>NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(NotificationService.this);
  mBuilder.setSmallIcon(R.mipmap.ic_launcher);
  mBuilder.setContentTitle("New website change.");
  mBuilder.setContentText("Changed: " + url);
  
  Intent notificationIntent = new Intent(getContext(), MainActivity.class);
  Bundle b = new Bundle();
  b.putString("key", url);
  notificationIntent.putExtras(b);
  
  notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
  
  PendingIntent intent = PendingIntent.getActivity(getContext(), id, notificationIntent, 0);
  
  mBuilder.setContentIntent(intent);
  
  NotificationManager mNotificationManager = (NotificationManager) getSystemService(NotificationService.this.NOTIFICATION_SERVICE);
  mNotificationManager.notify(id, mBuilder.build());
  </code></pre>
  
  <p>And then inside the activity:</p>
  
  <pre><code>Bundle b = getIntent().getExtras();
  if(b != null) {
    url = b.getString("key");
    editText.setText(url);
    webView.loadUrl(url);
    webView.requestFocus();
  }
  </code></pre>
  
  <p>Any help will be welcome, I will release this app's code as open source, thanks.</p>