I am trying to save user preferences in Android with the following code:
import java.util.prefs.Preferences;
class MyClass {
void save() throws Exception {
_prefs.put("NAME","VALUE");
_prefs.flush(); // Throws exception
}
private final Preferences _prefs = Preferences.userNodeForPackage(MyClass.class);
}
... but the "flush" call generates the following exception:
W/java.util.prefs: Could not lock User prefs. Unix error code 2.
W/System.err: java.util.prefs.BackingStoreException: Couldn't get file lock.
I guessed it was a problem with permissions. So I added the following to AndroidManifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_USER_DICTIONARY" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
But I still get the exception.
How can I save user preferences in Android with the java.util.prefs.Preferences class?