SpSaveDataUtils

32 阅读1分钟
package com.alibaba.genie.panel.basic.utils;

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

public class SpSaveDataUtils {
    private static SpSaveDataUtils spSaveDataUtils = null;
    private static String SHARENAME = "save_open_api_data";

    public SpSaveDataUtils() {

    }

    public static SpSaveDataUtils getInstance() {
        if(spSaveDataUtils==null){
            synchronized (SpSaveDataUtils.class){
                if(spSaveDataUtils==null){
                    spSaveDataUtils = new SpSaveDataUtils();
                }
            }
        }
        return spSaveDataUtils;
    }

    public void save(Context context,String key,String value){
        SharedPreferences sharedPreferences = context.getSharedPreferences(SHARENAME,Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = sharedPreferences.edit();
        edit.putString(key, value);
        edit.apply();
    }

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