Skip to content

Commit 4eef232

Browse files
authored
Merge pull request #1276 from OneSignal/fix/notif_open_cold_start_launch_activity
Fix notification open not launching main activity by default on app cold start
2 parents 4b804ab + 14c340f commit 4eef232

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

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

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

2172-
static boolean startOrResumeApp(Activity inContext) {
2173-
Intent launchIntent = inContext.getPackageManager().getLaunchIntentForPackage(inContext.getPackageName());
2174-
logger.debug("startOrResumeApp from context: " + inContext + " isRoot: " + inContext.isTaskRoot() + " with launchIntent: " + launchIntent);
2175-
// Make sure we have a launcher intent.
2176-
if (launchIntent != null) {
2177-
if (inContext.isTaskRoot()) {
2178-
inContext.startActivity(launchIntent);
2179-
} else {
2180-
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2181-
PendingIntent.getActivity(inContext, 0, launchIntent, 0);
2182-
}
2183-
return true;
2184-
}
2185-
return false;
2172+
static boolean startOrResumeApp(Activity activity) {
2173+
Intent launchIntent = activity.getPackageManager().getLaunchIntentForPackage(activity.getPackageName());
2174+
logger.debug("startOrResumeApp from context: " + activity + " isRoot: " + activity.isTaskRoot() + " with launchIntent: " + launchIntent);
2175+
2176+
// Not all apps have a launcher intent, such as one that only provides a homescreen widget
2177+
if (launchIntent == null)
2178+
return false;
2179+
2180+
activity.startActivity(launchIntent);
2181+
return true;
21862182
}
21872183

21882184
/**

0 commit comments

Comments
 (0)