Notification not starting a activity in android

android, android-activity, notifications, service

Solution

Replace `PendingIntent.getService(NotificationService.this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);`

With `PendingIntent.getActivity(NotificationService.this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);`

Notice the getService is replaced with getActivity.

Problem

I am developing a small app in which I want a background service to send a notification and when the user clicks the notification it must launch the appropriate activity. I am posting the code here for the notification and my problem is that the notification gets displayed on the status bar but when i click it it does not launch the activity. Can somebody suggest where I am going wrong. Please help. ``` NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification notification = new Notification(R.drawable.ic_launcher, "A New Message!", System.currentTimeMillis()); Intent notificationIntent = new Intent(NotificationService.this, com.jeris.android.MetroActivity.class); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent .getService(NotificationService.this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT); notification.setLatestEventInfo(NotificationService.this, "Bullion", "Rates for "+ parsedDate+"has not been updated. Go to app to check rates", pendingIntent); notificationManager.notify(11, notification); ```

Original source