您的位置:首页 > Web前端

【移动开发】SharedPreferences的兼容版本

2014-10-23 13:25 197 查看
public class SharedPreferencesCompat {
private static final String TAG = SharedPreferencesCompat.class
.getCanonicalName();
private static final Method sApplyMethod = findApplyMethod();

private static Method findApplyMethod() {
try {
Class<?> cls = SharedPreferences.Editor.class;
return cls.getMethod("apply");
} catch (NoSuchMethodException unused) {
// fall through
}
return null;
}

public static void apply(SharedPreferences.Editor editor) {
if (sApplyMethod != null) {
try {
sApplyMethod.invoke(editor);
Log.d(TAG, "Apply method was invoked!");
return;
} catch (InvocationTargetException unused) {
// fall through
} catch (IllegalAccessException unused) {
// fall through
}
}
editor.commit();
Log.d(TAG, "Commit method was invoked!");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: