Writing to Shared Preferences - Android Android OS

Android examples for Android OS:SharedPreferences

Description

Writing to Shared Preferences

Demo Code


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

public class Main {
    /**// ww w.j  a  va2 s.co  m
     * Writing to Preferences
     */

    public static void writeToPrefs(Context ctx, String key, String value) {
        ctx.getSharedPreferences(ctx.getApplicationInfo().packageName,
                ctx.MODE_PRIVATE).edit().putString(key, value).apply();
    }

    public static void writeToPrefs(Context ctx, String key, boolean value) {
        ctx.getSharedPreferences(ctx.getApplicationInfo().packageName,
                ctx.MODE_PRIVATE).edit().putBoolean(key, value).apply();
    }
}

Related Tutorials