@@ -390,26 +390,33 @@ public void onSwitchToBackground() {}
390
390
};
391
391
392
392
private void onForeground () {
393
- boolean systemNotificationEnabled = NotificationManagerCompat .from (_applicationContext ).areNotificationsEnabled ();
394
- SharedPreferences sharedPref = sharedInstance .getMainActivityContext ().getSharedPreferences (IterableConstants .SHARED_PREFS_FILE , Context .MODE_PRIVATE );
395
- boolean isNotificationEnabled = sharedPref .getBoolean (IterableConstants .SHARED_PREFS_DEVICE_NOTIFICATIONS_ENABLED , false );
396
-
397
393
if (!_firstForegroundHandled ) {
398
394
_firstForegroundHandled = true ;
395
+ if (sharedInstance .config .autoPushRegistration && sharedInstance .isInitialized ()) {
396
+ sharedInstance .registerForPush ();
397
+ }
399
398
fetchRemoteConfiguration ();
400
399
}
401
400
402
- if (sharedInstance .config .autoPushRegistration && sharedInstance .isInitialized () && isNotificationEnabled != systemNotificationEnabled ) {
403
- if (systemNotificationEnabled ) {
404
- sharedInstance .registerForPush ();
405
- } else {
406
- sharedInstance .disablePush ();
401
+ boolean systemNotificationEnabled = NotificationManagerCompat .from (_applicationContext ).areNotificationsEnabled ();
402
+ SharedPreferences sharedPref = sharedInstance .getMainActivityContext ().getSharedPreferences (IterableConstants .SHARED_PREFS_FILE , Context .MODE_PRIVATE );
403
+
404
+ boolean hasStoredPermission = sharedPref .contains (IterableConstants .SHARED_PREFS_DEVICE_NOTIFICATIONS_ENABLED );
405
+ boolean isNotificationEnabled = sharedPref .getBoolean (IterableConstants .SHARED_PREFS_DEVICE_NOTIFICATIONS_ENABLED , false );
406
+
407
+ if (sharedInstance .isInitialized ()) {
408
+ if (hasStoredPermission && (isNotificationEnabled != systemNotificationEnabled )) {
409
+ if (!systemNotificationEnabled ) {
410
+ sharedInstance .disablePush ();
411
+ } else {
412
+ sharedInstance .registerForPush ();
413
+ }
407
414
}
408
- }
409
415
410
- SharedPreferences .Editor editor = sharedPref .edit ();
411
- editor .putBoolean (IterableConstants .SHARED_PREFS_DEVICE_NOTIFICATIONS_ENABLED , systemNotificationEnabled );
412
- editor .apply ();
416
+ SharedPreferences .Editor editor = sharedPref .edit ();
417
+ editor .putBoolean (IterableConstants .SHARED_PREFS_DEVICE_NOTIFICATIONS_ENABLED , systemNotificationEnabled );
418
+ editor .apply ();
419
+ }
413
420
}
414
421
415
422
private boolean isInitialized () {
0 commit comments