Skip to content

Instantly share code, notes, and snippets.

@vuhung3990
Created October 4, 2014 08:27
Show Gist options
  • Save vuhung3990/d9351761fedcb45811e2 to your computer and use it in GitHub Desktop.
Save vuhung3990/d9351761fedcb45811e2 to your computer and use it in GitHub Desktop.
public static void setDefaultPreference(Context context,String share_Pref_Name) {
SharedPreferences getpref = context.getSharedPreferences(share_Pref_Name, Context.MODE_PRIVATE);
Map<String, ?> tempPreference = getpref.getAll();
if(tempPreference.size() <= 0){
// set default (fist time)
Editor edit = getpref.edit();
edit.putString(context.getString(R.string.pref_key_cache_capacity), StaticVar.PREF_DEFAULT_CACHE);
edit.putString(context.getString(R.string.pref_key_cache_mode), StaticVar.PREF_DEFAULT_CACHE_MODE);
edit.putBoolean(context.getString(R.string.pref_key_notification), StaticVar.PREF_DEFAULT_NOTIFICATION);
edit.putString(context.getString(R.string.pref_key_orientation_mode), StaticVar.PREF_DEFAULT_ORIENTATION_MODE);
edit.putBoolean(context.getString(R.string.pref_key_search_by_author), StaticVar.PREF_DEFAULT_SEARCH_BY_AUTHOR);
edit.putBoolean(context.getString(R.string.pref_key_search_by_desc), StaticVar.PREF_DEFAULT_SEARCH_BY_DESC);
edit.putBoolean(context.getString(R.string.pref_key_video_mode), StaticVar.PREF_DEFAULT_VIDEO_MODE);
edit.putBoolean(context.getString(R.string.pref_key_wifi_only), StaticVar.PREF_DEFAULT_WIFI_ONLY_MODE);
edit.commit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment