简体   繁体   中英

Pending Intent in Notification not working Android

My pending intent not working as to be expected to work.

Issue is: When tapping on Notification it redirects to Splash Activity that is my launcher Activity of application, following is my code for creating notification.

  Intent intent = new Intent(this, QuickTasks.class).putExtra("NOTIFICATION", 1);
  intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent resultIntent = PendingIntent.getActivity(this, 0, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri notificationSoundURI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder mNotificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle("Suvi")
            .setContentText(messageBody)
            .setAutoCancel(true)
            .setSound(notificationSoundURI)
            .setContentIntent(resultIntent);

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

    notificationManager.notify(0, mNotificationBuilder.build());     

Please help me in this regard i have used many of resources available here, but none of worked. Any help could be appreciable.

Generally, when you want to start an activity from a notification , there is two cases:

  1. Regular Activity: You're starting an Activity that's part of the application's normal workflow.
  2. Special Activity: The user only sees this Activity if it's started from a notification. In a sense, the Activity extends the notification by providing information that would be hard to display in the notification itself.

Please refer to the following link.
Preserving Navigation when Starting an Activity
I hope this helps you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM