Skip to content

Commit 0a5d33b

Browse files
committed
Fixes default notif open behavior to resume app
* This fix prevents notification opens affecting the Activity backstack * Fixes issue where if the app's main Activity was not the last Activity opened tapping on a notification would create another instance of it.  - Basically this behavior fix aligns with everything an Android Launcher would do. * This was the original intended behavior when this SDK switched from a BroadcastReceiver PendingIntent to an Activity PendingIntent when generating a notification.
1 parent 14c340f commit 0a5d33b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2169,15 +2169,28 @@ static void applicationOpenedByNotification(@Nullable final String notificationI
21692169
sessionManager.onDirectInfluenceFromNotificationOpen(appEntryState, notificationId);
21702170
}
21712171

2172-
static boolean startOrResumeApp(Activity activity) {
2172+
// This opens the app in the same way an Android homescreen launcher does.
2173+
// This means we expect the following behavior:
2174+
// 1. Starts the Activity defined in the app's AndroidManifest.xml as "android.intent.action.MAIN"
2175+
// 2. If the app is already running, instead the last activity will be resumed
2176+
// 3. If the app is not running (due to being push out of memory), the last activity will be resumed
2177+
// 4. If the app is no longer in the recent apps list, it is not resumed, same as #1 above.
2178+
// - App is removed from the recent app's list if it is swiped away or "clear all" is pressed.
2179+
static boolean startOrResumeApp(@NonNull Activity activity) {
21732180
Intent launchIntent = activity.getPackageManager().getLaunchIntentForPackage(activity.getPackageName());
21742181
logger.debug("startOrResumeApp from context: " + activity + " isRoot: " + activity.isTaskRoot() + " with launchIntent: " + launchIntent);
21752182

21762183
// Not all apps have a launcher intent, such as one that only provides a homescreen widget
21772184
if (launchIntent == null)
21782185
return false;
21792186

2187+
// Removing package from the intent, this treats the app as if it was started externally.
2188+
// This gives us the resume app behavior noted above.
2189+
// Android 11 no longer requires nulling this out to get this behavior.
2190+
launchIntent.setPackage(null);
2191+
21802192
activity.startActivity(launchIntent);
2193+
21812194
return true;
21822195
}
21832196

0 commit comments

Comments
 (0)