@Override public void run() { if (context == null) context = ZeroMusicApplication.getInstence(); if (TextUtils.isEmpty(configName) || TextUtils.isEmpty(configKey)) { return; } SharedPreferences.Editor sharedata = context.getSharedPreferences(configName, 0).edit(); if (configValue instanceof Integer) { sharedata.putInt(configKey, (Integer) configValue); } else if (configValue instanceof String) { sharedata.putString(configKey, (String) configValue); } else if (configValue instanceof Boolean) { sharedata.putBoolean(configKey, (Boolean) configValue); } else if (configValue instanceof Float) { sharedata.putFloat(configKey, (Float) configValue); } else if (configValue instanceof Long) { sharedata.putLong(configKey, (Long) configValue); } try { sharedata.commit(); if (this.commit != null) { this.commit.onSharedataCommit(configKey, configValue); } } catch (Exception e) { e.printStackTrace(); } }
public static void removeConfig(Context context, String cfgName, String cfgKey) { if (context == null) { context = ZeroMusicApplication.getInstence().getApplicationContext(); } try { SharedPreferences shareData = context.getSharedPreferences(cfgName, 0); shareData.edit().remove(cfgKey); shareData.edit().commit(); } catch (Exception e) { e.printStackTrace(); } }
public static String getStringConfig( Context context, String cfgName, String cfgKey, String defVal) { if (context == null) context = ZeroMusicApplication.getInstence(); SharedPreferences shareData = context.getSharedPreferences(cfgName, Context.MODE_PRIVATE); return shareData.getString(cfgKey, defVal); }