diff --git a/app/src/main/java/app/fedilab/android/mastodon/services/CustomReceiver.java b/app/src/main/java/app/fedilab/android/mastodon/services/CustomReceiver.java index cfe03a9c3..ab5fbc4c1 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/services/CustomReceiver.java +++ b/app/src/main/java/app/fedilab/android/mastodon/services/CustomReceiver.java @@ -66,14 +66,16 @@ public class CustomReceiver extends MessagingReceiver { @Override public void onNewEndpoint(@Nullable Context context, @NotNull String endpoint, @NotNull String slug) { if (context != null) { - SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); - String storedEnpoint = sharedpreferences.getString(context.getString(R.string.SET_STORED_ENDPOINT)+slug, null); - if(storedEnpoint == null || !storedEnpoint.equalsIgnoreCase(endpoint)) { - PushNotifications - .registerPushNotifications(context, endpoint, slug); - SharedPreferences.Editor editor = sharedpreferences.edit(); - editor.putString(context.getString(R.string.SET_STORED_ENDPOINT)+slug, endpoint); - editor.apply(); + synchronized(this) { + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); + String storedEnpoint = sharedpreferences.getString(context.getString(R.string.SET_STORED_ENDPOINT)+slug, null); + if(storedEnpoint == null || !storedEnpoint.equals(endpoint)) { + PushNotifications + .registerPushNotifications(context, endpoint, slug); + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putString(context.getString(R.string.SET_STORED_ENDPOINT)+slug, endpoint); + editor.commit(); + } } } }