Создание намерения, которое запускает действие.
Настройте запуск действия в новой пустой задаче, вызвав setFlags()
с флагами FLAG_ACTIVITY_NEW_TASK
и FLAG_ACTIVITY_CLEAR_TASK
.
Создайте PendingIntent
, вызвав getActivity()
.
Как,
Intent notifyIntent = new Intent(this, ResultActivity.class);
// Set the Activity to start in a new, empty task
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_CLEAR_TASK);
// Create the PendingIntent
PendingIntent notifyPendingIntent = PendingIntent.getActivity(this, 0,
notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Затем вы можете передать PendingIntent как обычно:
NotificationCompat.Builder mNotificationBuilder= new NotificationCompat.Builder(this, "CHANNEL_ID");
builder.setContentIntent(notifyPendingIntent);
...
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(0, mNotificationBuilder.build());