为共享preferences整个aplication设置默认值 [英] Set default values for the SharedPreferences for the whole aplication
本文介绍了为共享preferences整个aplication设置默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在应用与编码的关键,应该是从应用程序的所有部分可见。它必须有一个缺省值,也可以从活动之一改变的能力。如何设置这个默认值?
I have the application with coding key, that should be visible from all parts of the application. It has to have a default value and an ability to be changed from one of the activities. How can I set this default value?
推荐答案
让我们说这是您的共享preferences:
Let's say this is your shared preferences:
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
您可以这样设置的默认值:
you can set the default value like this:
String username = sharedPreferences.getString("USER_NAME", "DEFAULT_VALUE");
这篇关于为共享preferences整个aplication设置默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文