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

后端 未结 3 1712
梦如初夏
梦如初夏 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:16

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

    prefsEditor.commit();
    

    change your code instead of this

    SharedPreferences preferences = getSharedPreferences("preferences_target_value", Context.MODE_PRIVATE);
    

    to this

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

提交回复
热议问题