Dreamer Dreamer - 11 months ago 80
Android Question

Notifications in android studio

I have questions about notifications in android studio I want to build an app with two buttons (add notification and the other one is remove notification) when I press add notification a notification is create with two addActions (one is Read it and the other one is Likeit ) if I press first addAction it take me to ResultActivity.class in my app and if i press the second addAction it take me to another activity called Main2Activity.class in my class when I implement this code the two addAxtions take me to the same activity what is the wrong of my code

protected void onCreate(Bundle savedInstanceState) {


NotificationManager nmanger;
static int id=1;

public void buclick(View view) {
NotificationCompat.Builder nbuild= (NotificationCompat.Builder) new NotificationCompat.Builder(this)
.setContentText("the raining is comming soon")

Intent resultIntent = new Intent(this, ResultActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
PendingIntent resultPendingIntent =stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT );

Intent resultIntent_2 = new Intent(this, Main2Activity.class);
TaskStackBuilder stackBuilder_2 = TaskStackBuilder.create(this);
PendingIntent resultPendingIntent_2 =stackBuilder_2.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT );

nbuild.addAction(R.drawable.computer,"Read it",resultPendingIntent);
nbuild.addAction(R.drawable.trashcan_empty,"Link it",resultPendingIntent_2);

nmanger =(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

public void removeclick(View view) {


enter image description here

Answer Source

As I can see you missed out a line of code right after nbuild.setContentIntent(resultPendingIntent);

You are just setting the first Intent but not the second.