Not getting the updated value of the shared preference in the service

后端 未结 3 1709
梦如初夏
梦如初夏 2021-01-06 05:57

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 n

3条回答
  •  旧巷少年郎
    2021-01-06 06:33

    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.

提交回复
热议问题