I have a strange situation with the shared preferences in my application. I am using Firebase messaging service and I would like to set a boolean value to true in shared preferences whenever I recieve a message.
here's a simple code I worte:
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
getApplicationContext().getSharedPreferences(ApplicationConstants.SHARED_PREFRENCES_KEY, MODE_PRIVATE).edit().putBoolean(getString(R.string.badge_settings_key), true).apply();
}
I access this boolean value later in one of my activities. As you can see I set true for the boolean value in this method.
The strange thing is that when my application is in forground(one of the activites are visible), this works perfectly and whenever I access this value it is still true. But when my app is in background and I recieve a message, the value remains false and will not change. Either the service won't trigger correctly or the shared preferences file will not save correctly.
What can I do to solve this?