get SharedPreferences from a service

前端 未结 1 1453
抹茶落季
抹茶落季 2021-01-18 19:57

I am trying to access shared preferences from a service. I have used the the following to save the value of text to a string...

SharedPreferences sharedPrefe         


        
1条回答
  •  借酒劲吻你
    2021-01-18 20:08

    I'm always using PreferenceManager.getDefaultSharedPreferences(context). This is the same for all Contexts in your application.

    A Service is a Context itself, so this would be sufficient:

    PreferenceManager.getDefaultSharedPreferences(this);
    

    0 讨论(0)
提交回复
热议问题