私の受信者の1人にローカル通知が設定されています。通知のオンクリック特定のアクティビティを開きたい。以下は私のコードです。ローカル通知をクリックするとアクティビティが開きます
NotificationCompat.Builder builder =
(NotificationCompat.Builder) new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Its Your day!!")
.setContentText(message)
.setAutoCancel(true);
Intent notificationIntent = new Intent(context, MainActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(contentIntent);
// Add as notification
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(times, builder.build());
しかし、これは機能しません。通知をクリックするとステータスバーから通知が削除されます。私は何か不足していますか?
あなたはアプリを閉じた後にしようとしたんでした。 MainActivityが有効な場合、SINGLE_TOPは 'onNewIntent()'にインテントを渡します。 – ADM