Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import com.google.gson.Gson;

public class Main {

    public static Boolean putObject(String preName, Context context, String key, Class<?> clazz, Object obj) {
        String str = new Gson().toJson(obj, clazz);
        SharedPreferences pre = context.getSharedPreferences(preName, Context.MODE_PRIVATE);
        Editor editor = pre.edit();
        editor.putString(key, str);
        return editor.commit();
    }

    public static Boolean putString(String preName, Context context, String key, String value) {
        SharedPreferences pre = context.getSharedPreferences(preName, Context.MODE_PRIVATE);
        Editor editor = pre.edit();
        editor.putString(key, value);
        return editor.commit();
    }
}