Android notification click does not open connected activity

I want to open an Activity when I click on a notification from the status bar. I saw that this is an answer to StackOverflow, but none of these answers work for me. This problem is observed only on Lollipop devices, and the best way to reproduce: 1. Launch the application. 2. Ground the application. 3. Receive a push notification. 4. Click on the notification and try with 3-4 push notifications.

Below is my code: I also tried the following:

  • adding Intent.ACTION_MAIN
  • Intent.CATEGORY_LAUNCHER for intent
  • PendingIntent.FLAG_UPDATE_CURRENT.
  • android: exported = "true" in my AndroidManifest.xml

but nothing works. I see this problem only on Lollipop devices. Please note that I see this problem intermittently. This has something to do with the intention of getting caching and not getting it. Please, help.

PendingIntent pendingIntent = getPendingIntent(context, payload); Builder notificationBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_stat) .setContentTitle(res.getString(R.string.app_name)) .setContentText(payload.getMessage()) .setTicker(payload.getMessage()) .setContentIntent(pendingIntent) .setSound(soundUri); private PendingIntent getPendingIntent(Context context, NotificationPayload payload) { int requestID = (int) System.currentTimeMillis(); Intent intent = new Intent(context, DeepLinkActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setPackage(BuildConfig.APPLICATION_ID); intent.putExtra(NotificationHelper.KEY_NOTIFICATION_PAYLOAD, payload); return PendingIntent.getActivity(context, requestID, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT); } 
+5
source share
2 answers

try adding the Intent.FLAG_ACTIVITY_CLEAR_TASK flag to the intent

 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 

this seems to solve my problem

+2
source

Have you set the pending notification method setContentIntent?

Try this, it works for me in all versions of api

  Intent intent = new Intent(this, TestActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.logo) .setContentTitle(getResources().getString(R.string.notification_title)) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); 
0
source

All Articles