以下是我的推送通知代码。问题是,当我点击推送通知时,它只会转到MainActivity而不是 PushNotificationActivity.java
P.S:当应用程序处于活动状态时,它可以正常工作。
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, PushNotificationActivity.class);
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.mipmap.ic_stat_exit)
.setContentTitle("My First Project")
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
.setAutoCancel(true)
.setColor(getResources().getColor(R.color.colorAccent))
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
.setTicker("tickertexxxxtt")
.setOngoing(true);
NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
bigTextStyle.setBigContentTitle(getString(R.string.title));
bigTextStyle.bigText(messageBody);
notificationBuilder.setStyle(bigTextStyle);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}