我正在开发一个小应用程序,其中我希望后台服务发送通知,并且当用户单击通知时,它必须启动相应的活动。我在此处发布了通知的代码,我的问题是通知显示在状态栏上,但当我单击它时,它无法启动活动。有人能建议我错在哪里吗?请帮忙。
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);