@@ -390,22 +390,24 @@ public void onSwitchToBackground() {}
390390 };
391391
392392 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-
397393 if (!_firstForegroundHandled ) {
398394 _firstForegroundHandled = true ;
399395 fetchRemoteConfiguration ();
400- }
401396
402- if (sharedInstance .config .autoPushRegistration && sharedInstance .isInitialized () && isNotificationEnabled != systemNotificationEnabled ) {
403- if (systemNotificationEnabled ) {
404- sharedInstance .registerForPush ();
405- } else {
406- sharedInstance .disablePush ();
407- }
408- }
397+ if (sharedInstance .config .autoPushRegistration && sharedInstance .isInitialized ()) {
398+ sharedInstance .registerForPush ();
399+ }
400+ }
401+
402+ boolean systemNotificationEnabled = NotificationManagerCompat .from (_applicationContext ).areNotificationsEnabled ();
403+ SharedPreferences sharedPref = sharedInstance .getMainActivityContext ().getSharedPreferences (IterableConstants .SHARED_PREFS_FILE , Context .MODE_PRIVATE );
404+ boolean isNotificationEnabled = sharedPref .getBoolean (IterableConstants .SHARED_PREFS_DEVICE_NOTIFICATIONS_ENABLED , false );
405+
406+ if (sharedInstance .isInitialized () && isNotificationEnabled != systemNotificationEnabled ) {
407+ if (!systemNotificationEnabled ) {
408+ sharedInstance .disablePush ();
409+ }
410+ }
409411
410412 SharedPreferences .Editor editor = sharedPref .edit ();
411413 editor .putBoolean (IterableConstants .SHARED_PREFS_DEVICE_NOTIFICATIONS_ENABLED , systemNotificationEnabled );
0 commit comments