title: Message is received several times from gcm
body: <p>When notification is received I send a broadcast, using this code.</p>
  
  <pre><code>Event event = requestManager.getEventById(comment.eventId);
          Intent intent = new Intent(NOTIFICATION_ACTION).putExtra(EventFragment.EVENT, event);
          builder.setContentIntent(PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
  </code></pre>
  
  <p>The broadcast opens different activities, when the app is running or not.</p>
  
  <pre><code>    public class NotificationBroadCastReceiver extends BroadcastReceiver {
      @Override
      public void onReceive(Context context, Intent intent) {
          Event event = intent.getParcelableExtra(EventFragment.EVENT);
          if (event != null) {
              if (MainActivity.isRunning()) {
                  Bundle args = new Bundle();
                  args.putParcelable(EventFragment.EVENT, event);
                  intent = OneFragmentActivity.getStartIntent(context, EventFragment.class, args, R.layout.toolbar);
              } else {
                  intent = new Intent(context, MainActivity.class);
                  intent.putExtra(MainActivity.COMMENT_NOTIFICATION_EVENT, event);
              }
          }
          intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP |
                  Intent.FLAG_ACTIVITY_SINGLE_TOP);
          context.startActivity(intent);
      }
  }
  </code></pre>
  
  <p>When I click on the notification, when the app is running everything is working as expected. But when I kill the application and open the notification. The activity is opened as expected, but the same notification is received again.</p>
  
  <p>Here is a gcm service code.</p>
  
  <pre><code>public class MyGcmListenerService extends GcmListenerService {
  
      public static final String NOTIFICATION_ACTION = "com.khevents.Notification";
  
      private void setupCommentNotification(Comment comment, Notification.Builder builder) throws IOException {
          RequestManager requestManager = EventsApp.getInstance().getRequestManager();
  
          VkUser vkUser = requestManager.getVkUserById(comment.userId);
          builder.setLargeIcon(BitmapUtilities.getBitmapFromURL(vkUser.avatar));
          builder.setContentTitle(vkUser.name + " " + vkUser.lastName);
          builder.setContentText(comment.text);
  
          Event event = requestManager.getEventById(comment.eventId);
          Intent intent = new Intent(NOTIFICATION_ACTION).putExtra(EventFragment.EVENT, event);
          builder.setContentIntent(PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
      }
  
      private Notification.Builder createNotification(GCMData data) throws IOException {
          Notification.Builder builder = new Notification.Builder(this);
          if (data.comment != null) {
              setupCommentNotification(data.comment, builder);
          }
          builder.setSmallIcon(R.drawable.add_icon);
          return builder;
      }
  
      @Override
      public void onCreate() {
          super.onCreate();
      }
  
      @Override
      public void onMessageReceived(String from, Bundle bundle) {
          super.onMessageReceived(from, bundle);
          String json = bundle.getString("data");
          Log.i("GCM", "message received: " + json);
          GCMData data = Json.readNoThrow(json, GCMData.class);
          if (data == null) {
              return;
          }
  
          try {
              Notification.Builder notification = createNotification(data);
  
              new Handler(getMainLooper()).post(new Runnable() {
                  @Override
                  public void run() {
                      postNotification(notification);
                  }
              });
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  
      private void postNotification(Notification.Builder builder) {
          Notifications.notify(this, 1, builder);
      }
  }
  </code></pre>