Android:在SharedPreferences.Editor上调用commit()时,如何正确抑制Lint警告-“考虑使用apply()”?

ban*_*ing 4 android lint android-studio

我需要commit()而不是对apply()我的更改SharedPreferences.Editor

SharedPreferences sharedPrefs = getSharedPreferences("MY_SHARED_PREFS_FILE_NAME", Context.MODE_PRIVATE);
SharedPreferences.Editor sharedPrefsEditor = sharedPrefs.edit();
sharedPrefsEditor.putBoolean("MY_BOOLEAN", true);
sharedPrefsEditor.commit(); // <-- I get the Lint warning on this line.
Run Code Online (Sandbox Code Playgroud)

但是Lint给我这个警告:

考虑改用apply ; commit会立即将其数据写入持久性存储,而apply将在后台对其进行处理...

如何抑制掉毛警告?

@SuppressWarnings("all")在我的方法签名之前添加可消除警告,但是是否可以使用更具体的String代替"all"?(在这里找不到任何内容。)

Com*_*are 6

@SuppressLint("ApplySharedPref") 为我工作。