Skip to content Skip to sidebar Skip to footer

Not Getting The Updated Value Of The Shared Preference In The Service

I am storing some value to a shared preference from an activity which launched from a widget. If I retrieve that value from the service started from the same widget, it is not the

Solution 1:

These values are cached per process.

If you are running on Android > 2.3 you must specify MODE_MULTI_PROCESS when you call getSharedPreferences (). If you are running on Android < 2.3 then it should just work correctly. If you are running on Android 2.3 then there is a bug in the shared preferences stuff and it doesn't work correctly across multiple processes no matter what you do.

Solution 2:

use commit() after updating values, call this to have any changes you perform in the Editor

prefsEditor.commit();

change your code instead of this

SharedPreferencespreferences= getSharedPreferences("preferences_target_value", Context.MODE_PRIVATE);

to this

SharedPreferencespreferences= getSharedPreferences("preferance name", Context.MODE_PRIVATE);

Solution 3:

In manifest file try removing

android:process=":my_process"

from service. Hope it will work.

Post a Comment for "Not Getting The Updated Value Of The Shared Preference In The Service"