From 2408a1e6c52217c2112ce72a89f240f9bcc91cf1 Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Thu, 9 Jul 2020 11:30:44 -0500 Subject: [PATCH] Fix notification intent flags --- app/src/main/AndroidManifest.xml | 3 +-- .../notifications/NotificationManager.java | 8 +------ .../tasks/reminders/NotificationActivity.java | 21 +++++++++---------- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 432c26e84..1b2850430 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -293,9 +293,8 @@ diff --git a/app/src/main/java/org/tasks/notifications/NotificationManager.java b/app/src/main/java/org/tasks/notifications/NotificationManager.java index 3013433fc..3352df89b 100644 --- a/app/src/main/java/org/tasks/notifications/NotificationManager.java +++ b/app/src/main/java/org/tasks/notifications/NotificationManager.java @@ -1,7 +1,5 @@ package org.tasks.notifications; -import static android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK; -import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; import static androidx.core.app.NotificationCompat.FLAG_INSISTENT; import static androidx.core.app.NotificationCompat.FLAG_NO_CLEAR; import static com.google.common.collect.Iterables.concat; @@ -371,11 +369,7 @@ public class NotificationManager { .setShowWhen(true) .setTicker(taskTitle); - final Intent intent = new Intent(context, NotificationActivity.class); - intent.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_MULTIPLE_TASK); - intent.setAction("NOTIFY" + id); // $NON-NLS-1$ - intent.putExtra(NotificationActivity.EXTRA_TASK_ID, id); - intent.putExtra(NotificationActivity.EXTRA_TITLE, taskTitle); + Intent intent = NotificationActivity.newIntent(context, taskTitle, id); builder.setContentIntent( PendingIntent.getActivity(context, (int) id, intent, PendingIntent.FLAG_UPDATE_CURRENT)); diff --git a/app/src/main/java/org/tasks/reminders/NotificationActivity.java b/app/src/main/java/org/tasks/reminders/NotificationActivity.java index 9c754bc8d..cd6dcfc3e 100644 --- a/app/src/main/java/org/tasks/reminders/NotificationActivity.java +++ b/app/src/main/java/org/tasks/reminders/NotificationActivity.java @@ -1,5 +1,6 @@ package org.tasks.reminders; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import androidx.fragment.app.FragmentManager; @@ -28,6 +29,14 @@ public class NotificationActivity extends InjectingAppCompatActivity @Inject TaskDaoBlocking taskDao; @Inject ThemeAccent themeAccent; + public static Intent newIntent(Context context, String title, long id) { + Intent intent = new Intent(context, NotificationActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + intent.putExtra(NotificationActivity.EXTRA_TASK_ID, id); + intent.putExtra(NotificationActivity.EXTRA_TITLE, title); + return intent; + } + private long taskId; private CompositeDisposable disposables; @@ -37,17 +46,7 @@ public class NotificationActivity extends InjectingAppCompatActivity themeAccent.applyStyle(getTheme()); - setup(getIntent()); - } - - @Override - protected void onNewIntent(Intent intent) { - super.onNewIntent(intent); - - setup(intent); - } - - private void setup(Intent intent) { + Intent intent = getIntent(); taskId = intent.getLongExtra(EXTRA_TASK_ID, 0L);