This article describes the implementation method of Android using SharedPreferences to store data. Share it for your reference, as follows:
When editing a text message, you suddenly receive a call. This way, you can save the text message content that has been edited before.
@Override public void onCreate(Bundle savedInstanceState) { (savedInstanceState); setContentView(); // Open /data/data/package name/shared_prefs/file in read-only mode SharedPreferences sharedPreferences = getSharedPreferences("huangbiao", MODE_WORLD_READABLE); //Get the value of the key as key, if there is no temp value as default, if there is a value of temp as key String temp = ("key", "default"); (this, temp, Toast.LENGTH_SHORT).show(); } @Override protected void onStop() { (); //Open or create new and edit the contents inside //SharedPreferences class is to get the data inside, and Editor class is to save the data inside edit = getSharedPreferences("huangbiao", Context.MODE_WORLD_READABLE).edit(); //Add xml data with key value to the file ("key", "value"); (); }
Data in the file
The path to the file is as follows: /data/data/package name/shared_prefs/
<?xml version='1.0' encoding='utf-8' standalone='yes' ?> <map> <string name="huangbiao">biaobiao</string> <string name="abc">abc</string> </map>
For more information about Android related content, please check out the topic of this site:Android file operation skills summary》、《A summary of SD card operation methods for Android programming and development》、《Android development introduction and advanced tutorial》、《Android resource operation skills summary》、《Android View View Tips Summary"and"Android control usage summary》
I hope this article will be helpful to everyone's Android programming design.