Devrath
Devrath

Reputation: 42824

Multiple notification click launching a same activity android

I have a notification set up :

private void sendNotificationForCancellation(String appointmentId, String title, String message) {
        //AppController.getSharedPreferences().edit().putString(Constants.CALL_CASE_ID, notifObject.getCaseDetails().getCaseID()).commit();
        Intent intent = new Intent(this, ActCallRequestsDetail.class);
        intent.putExtra("appointment_id", appointmentId);
        intent.putExtra("isAppIdAvailable", true);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_stat_note_plus)
                .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.app_icon))
                .setContentTitle(title)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
                .setContentText(message)
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);

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

        Random generator = new Random();
        notificationManager.notify(generator.nextInt(), notificationBuilder.build());
    }

On click of notification it opens a activity

Scenario-1:

. Scenario-2:

. How to solve the Scenario-2

Upvotes: 2

Views: 1550

Answers (1)

Devrath
Devrath

Reputation: 42824

Solution was just adding a new ID for PendingIntent reference

private void sendNotificationForCancellation(String appointmentId, String title, String message) {
        Random generator = new Random();
       //AppController.getSharedPreferences().edit().putString(Constants.CALL_CASE_ID, notifObject.getCaseDetails().getCaseID()).commit();
        Intent intent = new Intent(this, ActCallRequestsDetail.class);
        intent.putExtra("appointment_id", appointmentId);
        intent.putExtra("isAppIdAvailable", true);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        PendingIntent pendingIntent = PendingIntent.getActivity(this, generator.nextInt(), intent, PendingIntent.FLAG_ONE_SHOT);

        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_stat_note_plus)
                .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.app_icon))
                .setContentTitle(title)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
                .setContentText(message)
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);

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


        notificationManager.notify(generator.nextInt(), notificationBuilder.build());
    }

Upvotes: 8

Related Questions