本文整理了Java中android.content.SharedPreferences.getInt()
方法的一些代码示例,展示了SharedPreferences.getInt()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SharedPreferences.getInt()
方法的具体详情如下:
包路径:android.content.SharedPreferences
类名称:SharedPreferences
方法名:getInt
[英]Retrieve an int value from the preferences.
[中]从首选项中检索int值。
代码示例来源:origin: stackoverflow.com
SharedPreferences prefs = getPreferences(MODE_PRIVATE);
String restoredText = prefs.getString("text", null);
if (restoredText != null)
{
//mSaved.setText(restoredText, TextView.BufferType.EDITABLE);
int selectionStart = prefs.getInt("selection-start", -1);
int selectionEnd = prefs.getInt("selection-end", -1);
/*if (selectionStart != -1 && selectionEnd != -1)
{
mSaved.setSelection(selectionStart, selectionEnd);
}*/
}
代码示例来源:origin: stackoverflow.com
//--Init
int myvar = 12;
//--SAVE Data
SharedPreferences preferences = context.getSharedPreferences("MyPreferences", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("var1", myvar);
editor.commit();
//--READ data
myvar = preferences.getInt("var1", 0);
代码示例来源:origin: mikepenz/AboutLibraries
PackageInfo pi = Util.getPackageInfo(ctx);
SharedPreferences sharedPreferences = ctx.getSharedPreferences("aboutLibraries", Context.MODE_PRIVATE);
int lastCacheVersion = sharedPreferences.getInt("versionCode", -1);
boolean isCacheUpToDate = pi != null && lastCacheVersion == pi.versionCode;
String[] autoDetectedLibraries = sharedPreferences.getString("autoDetectedLibraries", "").split(DELIMITER);
sharedPreferences.edit()
.putInt("versionCode", pi.versionCode)
.putString("autoDetectedLibraries", autoDetectedLibrariesPref.toString())
.apply();
代码示例来源:origin: robolectric/robolectric
@Test
public void commit_shouldStoreValues() throws Exception {
editor.commit();
SharedPreferences anotherSharedPreferences = context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
assertTrue(anotherSharedPreferences.getBoolean("boolean", false));
assertThat(anotherSharedPreferences.getFloat("float", 666f)).isEqualTo(1.1f);
assertThat(anotherSharedPreferences.getInt("int", 666)).isEqualTo(2);
assertThat(anotherSharedPreferences.getLong("long", 666L)).isEqualTo(3L);
assertThat(anotherSharedPreferences.getString("string", "wacka wa")).isEqualTo("foobar");
assertThat(anotherSharedPreferences.getStringSet("stringSet", null)).isEqualTo(stringSet);
}
代码示例来源:origin: yigit/android-priority-jobqueue
@Test
public void createId() {
when(mockSharedPreferences.getInt(FrameworkScheduler.KEY_ID, 0)).thenReturn(33);
assertThat(fwScheduler.createId(), is(34));
verify(mockEditor).putInt(FrameworkScheduler.KEY_ID, 34);
}
代码示例来源:origin: stackoverflow.com
SharedPreferences settings;
settings = getSharedPreferences("PREF_NAME", Context.MODE_PRIVATE);
//get the sharepref
int id = settings.getInt("ID", 0);
//set the sharedpref
Editor editor = settings.edit();
editor.putInt("ID", "1");
editor.commit();
代码示例来源:origin: stackoverflow.com
SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE);
String restoredText = prefs.getString("text", null);
if (restoredText != null) {
String name = prefs.getString("name", "No name defined");//"No name defined" is the default value.
int idName = prefs.getInt("idName", 0); //0 is the default value.
}
代码示例来源:origin: ankidroid/Anki-Android
preferences.edit().remove("noSpaceLeft").apply();
} else if (preferences.getString("lastVersion", "").equals("")) {
preferences.edit().putString("lastVersion", VersionUtils.getPkgVersionName()).apply();
onFinishedStartup();
} else if (skip < 2 && !preferences.getString("lastVersion", "").equals(VersionUtils.getPkgVersionName())) {
} else {
try {
previous = preferences.getInt("lastUpgradeVersion", current);
Timber.i("Previous AnkiDroid version: %s", previous);
} catch (ClassCastException e) {
String s = preferences.getString("lastUpgradeVersion", "");
preferences.edit().putInt("lastUpgradeVersion", current).apply();
代码示例来源:origin: f2prateek/rx-preferences
@Test public void set() {
rxPreferences.getBoolean("foo1").set(false);
assertThat(preferences.getBoolean("foo1", true)).isFalse();
rxPreferences.getEnum("foo2", PAPER, Roshambo.class).set(ROCK);
assertThat(preferences.getString("foo2", null)).isEqualTo("ROCK");
rxPreferences.getFloat("foo3").set(1f);
assertThat(preferences.getFloat("foo3", 0f)).isEqualTo(1f);
rxPreferences.getInteger("foo4").set(1);
assertThat(preferences.getInt("foo4", 0)).isEqualTo(1);
rxPreferences.getLong("foo5").set(1L);
assertThat(preferences.getLong("foo5", 0L)).isEqualTo(1L);
rxPreferences.getString("foo6").set("bar");
assertThat(preferences.getString("foo6", null)).isEqualTo("bar");
rxPreferences.getStringSet("foo7").set(singleton("bar"));
assertThat(preferences.getStringSet("foo7", null)).isEqualTo(singleton("bar"));
rxPreferences.getObject("foo8", new Point(2, 3), pointConverter).set(new Point(1, 2));
assertThat(preferences.getString("foo8", null)).isEqualTo("1,2");
}
代码示例来源:origin: stackoverflow.com
public void storeIntArray(int[] array){
SharedPreferences.Editor edit= mContext.getSharedPreferences("NAME", Context.MODE_PRIVATE).edit();
edit.putInt("Count", array.length);
int count = 0;
for (int i: array){
edit.putInt("IntValue_" + count++, i);
}
edit.commit();
}
public int[] getFromPrefs(){
int[] ret;
SharedPreferences prefs = mContext.getSharedPreferences("NAME", Context.MODE_PRIVATE);
int count = prefs.getInt("Count", 0);
ret = new int[count];
for (int i = 0; i < count; i++){
ret[i] = prefs.getInt("IntValue_"+ i, i);
}
return ret;
}
代码示例来源:origin: androidquery/androidquery
private static void fixWebviewTip(Context context){
SharedPreferences prefs = context.getSharedPreferences(PREF_FILE, Context.MODE_PRIVATE);
if (prefs.getInt(DOUBLE_TAP_TOAST_COUNT, 1) > 0) {
prefs.edit().putInt(DOUBLE_TAP_TOAST_COUNT, 0).commit();
}
}
代码示例来源:origin: stackoverflow.com
public static void loadArray(Context mContext)
{
SharedPreferences mSharedPreference1 = PreferenceManager.getDefaultSharedPreferences(mContext);
sKey.clear();
int size = mSharedPreference1.getInt("Status_size", 0);
for(int i=0;i<size;i++)
{
sKey.add(mSharedPreference1.getString("Status_" + i, null));
}
}
代码示例来源:origin: ac-pm/Inspeckage
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SharedPreferences.Editor edit = mPrefs.edit();
if (isChecked) {
edit.putBoolean(Config.SP_SWITCH_AUTH, true);
} else {
edit.putBoolean(Config.SP_SWITCH_AUTH, false);
}
TextView txtLogin = (TextView) view.findViewById(R.id.txtLogin);
TextView txtPass = (TextView) view.findViewById(R.id.txtPass);
edit.putString(Config.SP_USER_PASS, txtLogin.getText()+":"+txtPass.getText());
edit.apply();
stopService();
String host = null;
int port = mPrefs.getInt(Config.SP_SERVER_PORT, 8008);
if(!mPrefs.getString(Config.SP_SERVER_HOST, "All interfaces").equals("All interfaces")){
host = mPrefs.getString(Config.SP_SERVER_HOST, "All interfaces");
}
startService(host,port);
}
});
代码示例来源:origin: udacity/ud851-Exercises
synchronized public static void incrementChargingReminderCount(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
int chargingReminders = prefs.getInt(KEY_CHARGING_REMINDER_COUNT, DEFAULT_COUNT);
SharedPreferences.Editor editor = prefs.edit();
editor.putInt(KEY_CHARGING_REMINDER_COUNT, ++chargingReminders);
editor.apply();
}
代码示例来源:origin: androidannotations/androidannotations
@Override
public Integer getOr(Integer defaultValue) {
try {
return sharedPreferences.getInt(key, defaultValue);
} catch (ClassCastException e) {
// The pref could be a String, if that is the case try this
// recovery bit
try {
String value = sharedPreferences.getString(key, "" + defaultValue);
return Integer.parseInt(value);
} catch (Exception e2) {
// our recovery bit failed. The problem is elsewhere. Send the
// original error
throw e;
}
}
}
代码示例来源:origin: ac-pm/Inspeckage
String port = String.valueOf(mPrefs.getInt(Config.SP_SERVER_PORT, 8008));
String host = "";
if(mPrefs.getString(Config.SP_SERVER_HOST, "All interfaces").equals("All interfaces")){
String[] adds = mPrefs.getString(Config.SP_SERVER_INTERFACES, "--").split(",");
for(int i=0; i<adds.length; i++){
if(!adds[i].equals("All interfaces"))
String ip = mPrefs.getString(Config.SP_SERVER_HOST, "127.0.0.1");
host = scheme + ip + ":" + port;
SharedPreferences.Editor edit = mPrefs.edit();
edit.putString(Config.SP_SERVER_IP, ip);
edit.apply();
代码示例来源:origin: udacity/ud851-Exercises
synchronized public static void incrementChargingReminderCount(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
int chargingReminders = prefs.getInt(KEY_CHARGING_REMINDER_COUNT, DEFAULT_COUNT);
SharedPreferences.Editor editor = prefs.edit();
editor.putInt(KEY_CHARGING_REMINDER_COUNT, ++chargingReminders);
editor.apply();
}
代码示例来源:origin: stackoverflow.com
public String[] loadArray(String arrayName, Context mContext) {
SharedPreferences prefs = mContext.getSharedPreferences("preferencename", 0);
int size = prefs.getInt(arrayName + "_size", 0);
String array[] = new String[size];
for(int i=0;i<size;i++)
array[i] = prefs.getString(arrayName + "_" + i, null);
return array;
}
代码示例来源:origin: ac-pm/Inspeckage
if (base64.equals(Base64.encodeBytes(mPrefs.getString(Config.SP_USER_PASS, "").getBytes()))) {
logged = true;
if (mPrefs.getString(Config.SP_PROXY_HOST, "").equals("")) {
String ip = session.getHeaders().get("http-client-ip");
if (ip != null && !ip.trim().equals("")) {
SharedPreferences.Editor edit = mPrefs.edit();
edit.putString(Config.SP_PROXY_HOST, ip);
edit.putString(Config.SP_PROXY_PORT, "4443");
html = html.replace("#ip_ws#", mPrefs.getString(Config.SP_SERVER_IP, "127.0.0.1"));
html = html.replace("#port_ws#", String.valueOf(mPrefs.getInt(Config.SP_WSOCKET_PORT, 8887)));
return ok(html);
} else if (uri.contains("/content/")) {
PackageDetail pd = new PackageDetail(mContext, mPrefs.getString(Config.SP_PACKAGE, ""));
SharedPreferences.Editor edit = mPrefs.edit();
edit.putString(Config.SP_EXP_ACTIVITIES, pd.getExportedActivities());
edit.putString(Config.SP_N_EXP_ACTIVITIES, pd.getNonExportedActivities());
代码示例来源:origin: udacity/ud851-Exercises
synchronized public static void incrementChargingReminderCount(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
int chargingReminders = prefs.getInt(KEY_CHARGING_REMINDER_COUNT, DEFAULT_COUNT);
SharedPreferences.Editor editor = prefs.edit();
editor.putInt(KEY_CHARGING_REMINDER_COUNT, ++chargingReminders);
editor.apply();
}
内容来源于网络,如有侵权,请联系作者删除!