Get int value from SharedPreferences - Android Android OS

Android examples for Android OS:SharedPreferences

Description

Get int value from SharedPreferences

Demo Code


//package com.java2s;

import android.content.Context;
import android.content.SharedPreferences;

public class Main {
    public static final String KEY = "org.aisen.android.activityhelp_key";
    private static Context mContext;

    public static int getIntShareData(String key, int defValue) {
        SharedPreferences sp = mContext.getSharedPreferences(KEY,
                Context.MODE_PRIVATE);
        return sp.getInt(key, defValue);
    }/*from   ww w. ja v a 2  s .  c o m*/

    public static int getIntShareData(String key) {
        SharedPreferences sp = mContext.getSharedPreferences(KEY,
                Context.MODE_PRIVATE);
        return sp.getInt(key, 0);
    }
}

Related Tutorials