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;

public class Main {
    public static String SHARED_PREFERENCES_FILE = "mySharedPref";

    public static void setSharePref(Context context, String key, int value, int mode) {
        SharedPreferences sharedPref = context.getSharedPreferences(SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE);

        SharedPreferences.Editor editor = sharedPref.edit();

        editor.putInt(key, value);

        editor.commit();
    }

    public static void setSharePref(Context context, String key, String value, int mode) {
        SharedPreferences sharedPref = context.getSharedPreferences(SHARED_PREFERENCES_FILE, mode);

        SharedPreferences.Editor editor = sharedPref.edit();

        editor.putString(key, value);

        editor.commit();
    }

    public static void setSharePref(Context context, String key, boolean value, int mode) {
        SharedPreferences sharedPref = context.getSharedPreferences(SHARED_PREFERENCES_FILE, mode);

        SharedPreferences.Editor editor = sharedPref.edit();

        editor.putBoolean(key, value);

        editor.commit();
    }
}