2

I have a piece of code on my android studio project:

private void sendNotification(String msg) {
        mNotificationManager = (NotificationManager)
                this.getSystemService(Context.NOTIFICATION_SERVICE);

        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, MainActivity.class), 0);

        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(this)
                        // .setSmallIcon(R.drawable.ic_stat_gcm)
                        .setContentTitle("New updates from StoriesCity!")
                        .setSmallIcon(R.drawable.ic_launcher)
                        .setStyle(new NotificationCompat.BigTextStyle()
                                .bigText(msg))
                        .setContentText(msg);


        mBuilder.setContentIntent(contentIntent);
        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    }

It's working fine and i see the notification, but when i click on it it does not go away..

Maybe it's because i'm using .notify ? Please help me modify the code to makeit disapeair on click.

I'm a beginner :)

Seyyed
  • 1,526
  • 3
  • 20
  • 30
Niranbd
  • 33
  • 7

2 Answers2

3

Use:

.setAutoCancel(true);

setAutoCancel

Strider
  • 4,452
  • 3
  • 24
  • 35
0

Set flag FLAG_CANCEL_CURRENT instead of 0

 PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, MainActivity.class), PendingIntent.FLAG_CANCEL_CURRENT);

Also

.setAoutoCancel(true)
Seyyed
  • 1,526
  • 3
  • 20
  • 30