@@ -824,21 +824,19 @@ private static void handleAmazonPurchase() {
824
824
// If we don't have a OneSignal player_id yet make the call to create it regardless of focus
825
825
private static void doSessionInit () {
826
826
// Check session time to determine whether to start a new session or not
827
- if (isPastOnSessionTime ()) {
828
- if (inForeground ) {
829
- logger .debug ("Starting new session" );
830
-
831
- OneSignalStateSynchronizer .setNewSession ();
832
- outcomeEventsController .cleanOutcomes ();
833
- sessionManager .restartSessionIfNeeded (getAppEntryState ());
834
- getInAppMessageController ().resetSessionLaunchTime ();
835
- setLastSessionTime (time .getCurrentTimeMillis ());
836
- }
837
- } else {
838
- logger .debug ("Continue on same session" );
839
-
827
+ if (shouldStartNewSession ()) {
828
+ logger .debug ("Starting new session with appEntryState: " + getAppEntryState ());
829
+
830
+ OneSignalStateSynchronizer .setNewSession ();
831
+ outcomeEventsController .cleanOutcomes ();
832
+ sessionManager .restartSessionIfNeeded (getAppEntryState ());
833
+ getInAppMessageController ().resetSessionLaunchTime ();
834
+ setLastSessionTime (time .getCurrentTimeMillis ());
835
+ } else if (isInForeground ()) {
836
+ logger .debug ("Continue on same session with appEntryState: " + getAppEntryState ());
840
837
sessionManager .attemptSessionUpgrade (getAppEntryState ());
841
838
}
839
+
842
840
getInAppMessageController ().initWithCachedInAppMessages ();
843
841
844
842
// We still want register the user to OneSignal if the SDK was initialized
@@ -2914,6 +2912,16 @@ static boolean isAppActive() {
2914
2912
return initDone && isInForeground ();
2915
2913
}
2916
2914
2915
+ private static boolean shouldStartNewSession () {
2916
+ if (!isInForeground ())
2917
+ return false ;
2918
+
2919
+ if (!isPastOnSessionTime ())
2920
+ return false ;
2921
+
2922
+ return true ;
2923
+ }
2924
+
2917
2925
private static boolean isPastOnSessionTime () {
2918
2926
long currentTimeMillis = OneSignal .getTime ().getCurrentTimeMillis ();
2919
2927
long lastSessionTime = getLastSessionTime ();
0 commit comments