title: Android : Duplicate Activity Getting created on Broadcast Receiver
body: <p>I have specified an activity in my GCMIntent service class that need to be opened whenever user receives broadcast from server. Below is code in my GCMIntent class:</p>
  
  <pre><code>private void sendNotification(String msg) {
  String payload=msg.substring(msg.indexOf("RequestResponse=")+20, msg.indexOf("from")-2);
  mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
  PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, ListActivity.class), 0);
  NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher).setContentTitle("xxx").setStyle(new NotificationCompat.BigTextStyle().bigText("Update List")).setContentText("Update List").setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL).setWhen(System.currentTimeMillis());
  
      mBuilder.setContentIntent(contentIntent);
      mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
  }
  </code></pre>
  
  <p>So on Broadcast message click my ListActivity is supposed to open which will refresh the List based on data received from server. Issue is if my ListActivity is opened in foreground so on broadcast click the ListActivity is created again and then I have practically 2 instance of same activity one over other. Its working fine if some other Activity is in foreground.
  I did some research and it seems that we shouldn't use the code to determine the foreground activity in production. Some posts suggest that using Activity Manager to know the current foreground activity is to be used only for debugging purpose.
  I know this </p>