All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yy.httpdns.util.SharedPreferencesUtil Maven / Gradle / Ivy

package com.yy.httpdns.util;

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

import com.yy.httpdns.log.DnsLog;

/**
 * Created by huangzhilong on 2016/8/16.
 */
public class SharedPreferencesUtil {
    public static final String TAG = "SharedPreferencesUtil";
    public static String FILE_NAME = "android-httpDns";

    public static void put(Context context, String key, String ip) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(FILE_NAME, context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(key, ip);
        editor.commit();
        DnsLog.i(TAG, "SharedPreferences put key:" + key + " ip:" + ip);
    }

    public static String get(Context context, String key) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(FILE_NAME, context.MODE_PRIVATE);
        String ip = sharedPreferences.getString(key, null);
        return ip;
    }

    public static void clear(Context context) {
        SharedPreferences sp = context.getSharedPreferences(FILE_NAME, context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.commit();
        DnsLog.i(TAG, "clear SharedPreferences");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy