本文章为原创,转载请保留出处:http://www.eyeandroid.com/thread-10633-1-1.html


Android中得到SharedPreference的方式有四种:

  • ContextWrapper.getSharedPreferences(String name, int mode)
  • Activity.getPreferences(int mode)
  • PreferenceManager.getSharedPreferences()
  • PreferenceManager.getDefaultSharedPreferences(Context context)

下面我们一起来跟踪下它们的源码:
1.ContextWrapper.getSharedPreferences(String name,int mode)
这种方式得到的SharedPreference是某个包名下共享的,并且是私有的,不能让其他的包访问,而且Name和mode不能设置。最终也会调用到ContextWrapper的getSharedPreferences

相关文章:

  • 2021-04-28
  • 2021-11-04
  • 2022-12-23
  • 2021-09-08
  • 2021-09-18
  • 2021-11-24
猜你喜欢
  • 2022-02-25
  • 2022-12-23
  • 2022-02-06
  • 2022-12-23
  • 2021-08-04
相关资源
相似解决方案