Example usage for android.content SharedPreferences getInt

List of usage examples for android.content SharedPreferences getInt

Introduction

In this page you can find the example usage for android.content SharedPreferences getInt.

Prototype

int getInt(String key, int defValue);

Source Link

Document

Retrieve an int value from the preferences.

Usage

From source file:Main.java

public static int getAge(Context context) {
    SharedPreferences sp = getSP(context);
    return sp.getInt("age", 0);
}

From source file:Main.java

public static Integer getDeviceID(Context c) {
    SharedPreferences prefs = getSharedPreferences(c);
    return prefs.getInt("device_id", 0);
}

From source file:Main.java

public static String[] loadArray(SharedPreferences prefs, String arrayName) {
    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;
}

From source file:Main.java

public static LinkedList<String> loadList(SharedPreferences prefs, String listName) {
    int size = prefs.getInt(listName + "_size", 0);
    LinkedList<String> list = new LinkedList<String>();
    for (int i = 0; i < size; i++) {
        list.add(prefs.getString(listName + "_" + i, null));
    }/* ww w  . j a  va 2  s .c o  m*/
    return list;
}

From source file:Main.java

public static int getPrefInt(Context context, String key) {
    SharedPreferences prefs = getPreferences(context);
    int value = prefs.getInt(key, 0);
    return value;
}

From source file:Main.java

public static void deleteSet(SharedPreferences prefs, String setName) {
    final int size = prefs.getInt(setName + "_size", 0);
    Editor editor = prefs.edit();//from   w  w  w.j av a  2 s.c  o m
    for (int i = 0; i < size; i++)
        editor.remove(setName + "_" + i);
    editor.remove(setName + "_size");
    editor.commit();
}

From source file:Main.java

public static int getInt(Context context, String key, int defValue) {
    SharedPreferences sp = getSharedPreferences(context);
    return sp.getInt(key, defValue);
}

From source file:Main.java

public static int getIntFromSP(Context context, String key) {
    SharedPreferences sp = getSharedPreferences(context);
    return sp.getInt(key, 0);
}

From source file:Main.java

public static int getIntFromSP(Context context, String key, int def) {
    SharedPreferences sp = getSharedPreferences(context);
    return sp.getInt(key, def);
}

From source file:Main.java

public static Set<String> loadSet(SharedPreferences prefs, String setName) {
    final int size = prefs.getInt(setName + "_size", 0);
    Set<String> set = new HashSet<String>(size);
    for (int i = 0; i < size; i++)
        set.add(prefs.getString(setName + "_" + i, null));
    return set;/*from   w  w w . java 2 s  .  c  om*/
}