Java 离开SharedReferences&;编辑开放

Java 离开SharedReferences&;编辑开放,java,android,sharedpreferences,Java,Android,Sharedpreferences,e、 你有这门课吗 private SharedPreferences sp private SharedPreferences.Editor editor protected void onCreate(..) { this.sp = ... this.editor = this.sp.edit(); } 这样做不好吗?共享首选项正常,编辑器不正常。 只要不调用编辑器的commit或apply,这些值就不会写入preferences.file,我认为从sp读取时也不会得到这些值 因此,作为

e、 你有这门课吗

private SharedPreferences sp
private SharedPreferences.Editor editor

protected void onCreate(..) {
this.sp = ...
this.editor = this.sp.edit();
}

这样做不好吗?

共享首选项正常,编辑器不正常。 只要不调用编辑器的commit或apply,这些值就不会写入preferences.file,我认为从sp读取时也不会得到这些值

因此,作为一种习惯,在编写首选项值(Java)时总是这样做


或者putInt、putBoolean等。

应用()和提交()相同吗?应用是异步的,而提交是同步的
sp.edit().putString(key, value).apply()