Pending intent in notification not working Pending intent in notification not working android android

Pending intent in notification not working


try this:

private void setNotification(String notificationMessage) {//**add this line**int requestID = (int) System.currentTimeMillis();Uri alarmSound = getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);mNotificationManager  = getApplication().getSystemService(Context.NOTIFICATION_SERVICE);Intent notificationIntent = new Intent(getApplicationContext(), NotificationActivity2.class);//**add this line**notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); //**edit this line to put requestID as requestCode**PendingIntent contentIntent = PendingIntent.getActivity(this, requestID,notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext()).setSmallIcon(R.drawable.logo).setContentTitle("My Notification").setStyle(new NotificationCompat.BigTextStyle().bigText(notificationMessage)).setContentText(notificationMessage).setAutoCancel(true);mBuilder.setSound(alarmSound);mBuilder.setContentIntent(contentIntent);mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());}


You might be using a notification id equal to 0. There is known issue with notification id being 0. If you will use any other id, it should work.


I added task builder and the below block code worked for me

Intent intent = new Intent(context, HomeActivity.class);TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);stackBuilder.addParentStack(SplashActivity.class);stackBuilder.addNextIntent(intent);PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);