我不明白为什么它不会让我返回 sharePreferenceUtils。有一个更好的方法吗?我收到错误“类型不兼容”
private static String Preference_NAME = "CodeLotto";
private static SharePreferenceUtils sharePreferenceUtils;
private SharedPreferences sharedPreferences;
private SharePreferenceUtils(Context context){
Preference_NAME = Preference_NAME + context.getPackageName();
this.sharedPreferences = context.getSharedPreferences(Preference_NAME, Context.MODE_PRIVATE);
}
public static SharedPreferences getInstance(){
if (sharePreferenceUtils == null) {
sharePreferenceUtils = new SharePreferenceUtils(MyApp.getContext());
}
return sharePreferenceUtils;
}
public void saveString(String key, String Val){
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(key, Val);
editor.commit();
}
public String getString(String key, String defVal){
return sharedPreferences.getString(key, defVal);
}
public String getString(String key){
return sharedPreferences.getString(key, "");
}
}
幕布斯6054654
繁星点点滴滴
相关分类