Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.util.Log; public class Main { /** * to save in sharedpreference * * @param context context of calling activity * @param key key for storing * @param value value to be stored */ public static void setPreference(Context context, String key, String value) { logD("saving key:" + key + " value:" + value); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences.Editor editor = preferences.edit(); editor.putString(key, value); editor.apply(); } /** * log debug a string * * @param s string to be logged */ public static void logD(String s) { logD("LOG", s); } /** * log debug a string * * @param tag tag for logging * @param s string to be logged */ public static void logD(String tag, String s) { Log.d(tag, s); } }