Here you can find the source of putPrefs(Activity context, int mode, Map
Parameter | Description |
---|---|
context | - Activity context |
mode | - Mode to open shared preferences |
pairs | - map to put in shared preferences |
public static void putPrefs(Activity context, int mode, Map<String, String> pairs)
//package com.java2s; import java.util.Map; import java.util.Map.Entry; import android.app.Activity; import android.content.SharedPreferences; public class Main { /**/*from ww w . java2s . c om*/ * Purpose - Put preferences through the Shared Preferences API. * Use this from an activity if you need to use only one shared preference file for the activity * * @param context - Activity context * @param mode - Mode to open shared preferences * @param pairs - map to put in shared preferences * */ public static void putPrefs(Activity context, int mode, Map<String, String> pairs) { SharedPreferences prefs = context.getPreferences(mode); if (pairs != null && !pairs.isEmpty()) { SharedPreferences.Editor editor = prefs.edit(); for (Entry<String, String> pair : pairs.entrySet()) { editor.putString(pair.getKey(), pair.getValue()); } editor.commit(); } } }