Reputation: 14286
If we remove all setting from SharedPreferences stored under a certain key is the key removed? And if not how to remove it?
For instance:
SharedPreferences settings = getSharedPreferences("settings", MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.remove("username_field");
editor.remove("password_field");
editor.commit();
What happens with the "settings.xml" files stored?
Upvotes: 1
Views: 124
Reputation: 622
If the SharedPreference named 'settings' has 'username_field' and 'paddword_field',
the values and keys are all removed from 'settings' preference.
so when you open SharedPreference file - 'settings.xml' , you can't find that keys.
The other case, If the Shared preference doesn't have 'username_field' and 'paddword_field', nottings happened. no errors.
And If you understand 'change the SharedPreference named settings, it will change Android System Settings', see below.
SharedPreference stored locally.
The SharedPreference also stored at your own application package.
See the below.
package com.test.setting;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
public class TestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SharedPreferences settings = getSharedPreferences("settings", MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.putString("username_field","id");
editor.putString("password_field","1111");
editor.commit();
}
}
The package name of this application is 'com.test.setting'.
And SharedPreference's name is 'settings', and access mode is private.
So the Android creates 'settings.xml' file at the application's package.
and set the file permission 'rw-rw----'(prevent to access from another application).
Upvotes: 1