{"id":518,"date":"2023-07-29T04:01:55","date_gmt":"2023-06-04T15:48:29","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/index.php\/2023\/11\/30\/android%e5%85%b1%e4%ba%ab%e9%a6%96%e9%80%89%e9%a1%b9%e7%a4%ba%e4%be%8b%e6%95%99%e7%a8%8b\/"},"modified":"2025-08-02T15:20:42","modified_gmt":"2025-08-02T07:20:42","slug":"android%e5%85%b1%e4%ba%ab%e9%a6%96%e9%80%89%e9%a1%b9%e7%a4%ba%e4%be%8b%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/android%e5%85%b1%e4%ba%ab%e9%a6%96%e9%80%89%e9%a1%b9%e7%a4%ba%e4%be%8b%e6%95%99%e7%a8%8b\/","title":{"rendered":"Android SharedPreferences\u5b8c\u5168\u6307\u5357\uff1a\u4ece\u5165\u95e8\u5230\u7cbe\u901a\u7684\u5171\u4eab\u9996\u9009\u9879\u6559\u7a0b"},"content":{"rendered":"<p>\u8fd9\u662f\u6587\u7ae0\u300aAndroid\u5171\u4eab\u9996\u9009\u9879\u793a\u4f8b\u6559\u7a0b\u300b\u7684\u7b2c1\u90e8\u5206\uff08\u51712\u90e8\u5206\uff09\u3002<\/p>\n<p>\u5185\u5bb9\u7247\u6bb5\uff1a\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u4f7f\u7528Android\u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u5171\u4eab\u9996\u9009\u9879\uff08Shared Preferences\uff09\u6765\u4ee5\u952e\u503c\u5bf9\u7684\u5f62\u5f0f\u5b58\u50a8\u6570\u636e\u3002<\/p>\n<h3>Android\u5171\u4eab\u9996\u9009\u9879\u6982\u8ff0<\/h3>\n<p>\u5171\u4eab\u9996\u9009\u9879\u5141\u8bb8\u6d3b\u52a8\u548c\u5e94\u7528\u7a0b\u5e8f\u4fdd\u7559\u504f\u597d\u8bbe\u7f6e\uff0c\u4ee5\u952e\u503c\u5bf9\u7684\u5f62\u5f0f\u5b58\u50a8\uff0c\u7c7b\u4f3c\u4e8eMap\uff0c\u5373\u4f7f\u7528\u6237\u5173\u95ed\u5e94\u7528\u7a0b\u5e8f\uff0c\u8fd9\u4e9b\u504f\u597d\u8bbe\u7f6e\u4e5f\u4f1a\u6301\u4e45\u5316\u3002Android\u5c06\u5171\u4eab\u9996\u9009\u9879\u8bbe\u7f6e\u5b58\u50a8\u4e3aXML\u6587\u4ef6\uff0c\u4f4d\u4e8eDATA\/data\/{\u5e94\u7528\u7a0b\u5e8f\u5305}\u76ee\u5f55\u4e0b\u7684shared_prefs\u6587\u4ef6\u5939\u4e2d\u3002\u901a\u8fc7\u8c03\u7528Environment.getDataDirectory()\u53ef\u4ee5\u83b7\u53d6DATA\u6587\u4ef6\u5939\u3002SharedPreferences\u662f\u5e94\u7528\u7a0b\u5e8f\u7279\u5b9a\u7684\uff0c\u5373\u5728\u6267\u884c\u4ee5\u4e0b\u9009\u9879\u4e4b\u4e00\u65f6\u6570\u636e\u4f1a\u4e22\u5931\uff1a<\/p>\n<ul class=\"post-ul\">\n<li>\u5378\u8f7d\u5e94\u7528\u7a0b\u5e8f\u65f6<\/li>\n<li>\u6e05\u9664\u5e94\u7528\u7a0b\u5e8f\u6570\u636e\u65f6\uff08\u901a\u8fc7\u8bbe\u7f6e\uff09<\/li>\n<\/ul>\n<p>\u6b63\u5982\u5176\u540d\uff0c\u4e3b\u8981\u76ee\u7684\u662f\u5b58\u50a8\u7528\u6237\u6307\u5b9a\u7684\u914d\u7f6e\u7ec6\u8282\uff0c\u4f8b\u5982\u7528\u6237\u7279\u5b9a\u7684\u8bbe\u7f6e\uff0c\u4f7f\u7528\u6237\u4fdd\u6301\u767b\u5f55\u72b6\u6001\u3002\u4e3a\u4e86\u8bbf\u95ee\u504f\u597d\u8bbe\u7f6e\uff0c\u6211\u4eec\u6709\u4e09\u4e2a\u53ef\u4f9b\u9009\u62e9\u7684API\u3002<\/p>\n<ul class=\"post-ul\">\n<li>getPreferences()\uff1a\u5728Activity\u5185\u90e8\u4f7f\u7528\uff0c\u7528\u4e8e\u8bbf\u95ee\u6d3b\u52a8\u7279\u5b9a\u7684\u504f\u597d\u8bbe\u7f6e<\/li>\n<li>getSharedPreferences()\uff1a\u5728Activity\uff08\u6216\u5176\u4ed6\u5e94\u7528\u7a0b\u5e8f\u4e0a\u4e0b\u6587\uff09\u4e2d\u4f7f\u7528\uff0c\u7528\u4e8e\u8bbf\u95ee\u5e94\u7528\u7a0b\u5e8f\u7ea7\u522b\u7684\u504f\u597d\u8bbe\u7f6e<\/li>\n<li>getDefaultSharedPreferences()\uff1a\u5728PreferenceManager\u4e0a\u4f7f\u7528\uff0c\u7528\u4e8e\u83b7\u53d6\u4e0eAndroid\u6574\u4f53\u504f\u597d\u6846\u67b6\u534f\u540c\u5de5\u4f5c\u7684\u5171\u4eab\u9996\u9009\u9879<\/li>\n<\/ul>\n<p>\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u4f7f\u7528getSharedPreferences()\u65b9\u6cd5\u3002\u8be5\u65b9\u6cd5\u7684\u5b9a\u4e49\u5982\u4e0b\uff1agetSharedPreferences(String PREFS_NAME, int mode)\uff0c\u5176\u4e2dPREFS_NAME\u662f\u6587\u4ef6\u7684\u540d\u79f0\uff0cmode\u662f\u64cd\u4f5c\u6a21\u5f0f\u3002\u4ee5\u4e0b\u662f\u53ef\u9002\u7528\u7684\u64cd\u4f5c\u6a21\u5f0f\uff1a<\/p>\n<ul class=\"post-ul\">\n<li>MODE_PRIVATE\uff1a\u9ed8\u8ba4\u6a21\u5f0f\uff0c\u521b\u5efa\u7684\u6587\u4ef6\u53ea\u80fd\u7531\u8c03\u7528\u5e94\u7528\u7a0b\u5e8f\u8bbf\u95ee<\/li>\n<li>MODE_WORLD_READABLE\uff1a\u521b\u5efa\u5168\u5c40\u53ef\u8bfb\u6587\u4ef6\u975e\u5e38\u5371\u9669\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5e94\u7528\u7a0b\u5e8f\u51fa\u73b0\u5b89\u5168\u6f0f\u6d1e<\/li>\n<li>MODE_WORLD_WRITEABLE\uff1a\u521b\u5efa\u5168\u5c40\u53ef\u5199\u6587\u4ef6\u975e\u5e38\u5371\u9669\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5e94\u7528\u7a0b\u5e8f\u51fa\u73b0\u5b89\u5168\u6f0f\u6d1e<\/li>\n<li>MODE_MULTI_PROCESS\uff1a\u5373\u4f7f\u5171\u4eab\u9996\u9009\u9879\u5b9e\u4f8b\u5df2\u7ecf\u52a0\u8f7d\uff0c\u6b64\u65b9\u6cd5\u4e5f\u4f1a\u68c0\u67e5\u504f\u597d\u7684\u4fee\u6539<\/li>\n<li>MODE_APPEND\uff1a\u8fd9\u4f1a\u5c06\u65b0\u7684\u504f\u597d\u8bbe\u7f6e\u4e0e\u5df2\u5b58\u5728\u7684\u504f\u597d\u8bbe\u7f6e\u8ffd\u52a0\u5728\u4e00\u8d77<\/li>\n<li>MODE_ENABLE_WRITE_AHEAD_LOGGING\uff1a\u6570\u636e\u5e93\u6253\u5f00\u6807\u5fd7\u3002\u5f53\u8bbe\u7f6e\u6b64\u6807\u5fd7\u65f6\uff0c\u9ed8\u8ba4\u4f1a\u542f\u7528\u9884\u5199\u65e5\u5fd7\u8bb0\u5f55<\/li>\n<\/ul>\n<h3>\u521d\u59cb\u5316<\/h3>\n<p>\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u7f16\u8f91\u5668\u6765\u7f16\u8f91\u5e76\u4fdd\u5b58\u5171\u4eab\u504f\u597d\u8bbe\u7f6e\u4e2d\u7684\u66f4\u6539\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u6765\u83b7\u53d6\u5171\u4eab\u504f\u597d\u8bbe\u7f6e\u3002<\/p>\n<pre class=\"post-pre\"><code>SharedPreferences pref = getApplicationContext().getSharedPreferences(\"MyPref\", 0); \/\/ 0 - \u8868\u793a\u79c1\u6709\u6a21\u5f0f\r\nEditor editor = pref.edit();\r\n<\/code><\/pre>\n<h3>\u5b58\u50a8\u6570\u636e<\/h3>\n<p>\u4e3a\u4e86\u4fdd\u5b58\u5171\u4eab\u53c2\u6570\u7684\u66f4\u6539\uff0c\u4f7f\u7528editor.commit()\u3002<\/p>\n<pre class=\"post-pre\"><code>editor.putBoolean(\"key_name\", true); \/\/ \u5b58\u50a8\u5e03\u5c14\u503c - true\/false\r\neditor.putString(\"key_name\", \"string value\"); \/\/ \u5b58\u50a8\u5b57\u7b26\u4e32\r\neditor.putInt(\"key_name\", \"int value\"); \/\/ \u5b58\u50a8\u6574\u6570\r\neditor.putFloat(\"key_name\", \"float value\"); \/\/ \u5b58\u50a8\u6d6e\u70b9\u6570\r\neditor.putLong(\"key_name\", \"long value\"); \/\/ \u5b58\u50a8\u957f\u6574\u578b\r\n \r\neditor.commit(); \/\/ \u63d0\u4ea4\u66f4\u6539\r\n<\/code><\/pre>\n<h3>\u83b7\u53d6\u6570\u636e<\/h3>\n<p>\u901a\u8fc7\u8c03\u7528getString()\u53ef\u4ee5\u4ece\u4fdd\u5b58\u7684\u9996\u9009\u9879\u4e2d\u68c0\u7d22\u6570\u636e\u3002<\/p>\n<pre class=\"post-pre\"><code>pref.getString(\"key_name\", null); \/\/ \u83b7\u53d6\u5b57\u7b26\u4e32\r\npref.getInt(\"key_name\", -1); \/\/ \u83b7\u53d6\u6574\u6570\r\npref.getFloat(\"key_name\", null); \/\/ \u83b7\u53d6\u6d6e\u70b9\u6570\r\npref.getLong(\"key_name\", null); \/\/ \u83b7\u53d6\u957f\u6574\u578b\r\npref.getBoolean(\"key_name\", null); \/\/ \u83b7\u53d6\u5e03\u5c14\u503c\r\n<\/code><\/pre>\n<h3>\u6e05\u9664\u6216\u5220\u9664\u6570\u636e<\/h3>\n<p>\u4f7f\u7528remove(&#8220;key_name&#8221;)\u4f1a\u5220\u9664\u7279\u5b9a\u7684\u503c\u3002\u800cclear()\u5219\u4f1a\u79fb\u9664\u6240\u6709\u7684\u6570\u636e\u3002<\/p>\n<pre class=\"post-pre\"><code>editor.remove(\"name\"); \/\/ \u5c06\u5220\u9664\u540d\u4e3aname\u7684\u952e\r\neditor.remove(\"email\"); \/\/ \u5c06\u5220\u9664\u540d\u4e3aemail\u7684\u952e\r\n \r\neditor.commit(); \/\/ \u63d0\u4ea4\u66f4\u6539\r\n<\/code><\/pre>\n<pre class=\"post-pre\"><code>editor.clear();\r\neditor.commit(); \/\/ \u63d0\u4ea4\u66f4\u6539\r\n<\/code><\/pre>\n<h3>\u9879\u76ee\u7ed3\u6784<\/h3>\n<h3>\u5b89\u5353\u5171\u4eab\u504f\u597d\u8bbe\u7f6e\u9879\u76ee\u7684\u4ee3\u7801<\/h3>\n<p>\u8fd9\u662f\u300aAndroid\u5171\u4eab\u9996\u9009\u9879\u793a\u4f8b\u6559\u7a0b\u300b\u7684\u7b2c\u4e8c\u90e8\u5206\uff08\u5171\u4e24\u90e8\u5206\uff09\u3002<\/p>\n<p>\u672c\u8282\u5185\u5bb9\uff1aactivity_main.xml \u5e03\u5c40\u6587\u4ef6\u5305\u542b\u4e24\u4e2a EditText \u89c6\u56fe\uff0c\u7528\u4e8e\u5b58\u50a8\u548c\u663e\u793a\u59d3\u540d\u548c\u7535\u5b50\u90ae\u4ef6\u3002\u4e09\u4e2a\u6309\u94ae\u5728 MainActivity \u4e2d\u5206\u522b\u5b9e\u73b0\u4e86\u5404\u81ea\u7684 onClick \u529f\u80fd\u3002<\/p>\n<pre class=\"post-pre\"><code>&lt;RelativeLayout xmlns:android=\"https:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"\r\n    android:paddingBottom=\"@dimen\/activity_vertical_margin\"\r\n    android:paddingLeft=\"@dimen\/activity_horizontal_margin\"\r\n    android:paddingRight=\"@dimen\/activity_horizontal_margin\"\r\n    android:paddingTop=\"@dimen\/activity_vertical_margin\" &gt;\r\n\r\n    &lt;Button\r\n        android:id=\"@+id\/btnSave\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_centerVertical=\"true\"\r\n        android:layout_alignParentLeft=\"true\"\r\n        android:layout_alignParentStart=\"true\"\r\n        android:onClick=\"Save\"\r\n        android:text=\"\u4fdd\u5b58\" \/&gt;\r\n\r\n    &lt;Button\r\n        android:id=\"@+id\/btnRetr\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_centerHorizontal=\"true\"\r\n        android:layout_centerVertical=\"true\"\r\n        android:onClick=\"Get\"\r\n        android:text=\"\u68c0\u7d22\" \/&gt;\r\n\r\n    &lt;Button\r\n        android:id=\"@+id\/btnClear\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_alignRight=\"@+id\/etEmail\"\r\n        android:layout_centerVertical=\"true\"\r\n        android:layout_alignParentRight=\"true\"\r\n        android:layout_alignParentEnd=\"true\"\r\n        android:onClick=\"clear\"\r\n        android:text=\"\u6e05\u9664\" \/&gt;\r\n\r\n    &lt;EditText\r\n        android:id=\"@+id\/etEmail\"\r\n        android:layout_width=\"match_parent\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:ems=\"10\"\r\n        android:hint=\"\u7535\u5b50\u90ae\u4ef6\"\r\n        android:inputType=\"textEmailAddress\"\r\n        android:layout_below=\"@+id\/etName\"\r\n        android:layout_marginTop=\"20dp\"\r\n        android:layout_alignParentRight=\"true\"\r\n        android:layout_alignParentEnd=\"true\" \/&gt;\r\n\r\n    &lt;EditText\r\n        android:id=\"@+id\/etName\"\r\n        android:layout_width=\"match_parent\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:ems=\"10\"\r\n        android:hint=\"\u59d3\u540d\"\r\n        android:inputType=\"text\"\r\n        android:layout_alignParentTop=\"true\"\r\n        android:layout_alignLeft=\"@+id\/etEmail\"\r\n        android:layout_alignStart=\"@+id\/etEmail\" \/&gt;\r\n\r\n&lt;\/RelativeLayout&gt;\r\n<\/code><\/pre>\n<p>MainActivity.java\u6587\u4ef6\u7528\u4e8e\u901a\u8fc7\u952e\u503c\u5bf9\u4fdd\u5b58\u548c\u68c0\u7d22\u6570\u636e\u3002<\/p>\n<pre class=\"post-pre\"><code>package com.Olivia.sharedpreferences;\r\n\r\nimport android.app.Activity;\r\nimport android.content.Context;\r\nimport android.content.SharedPreferences;\r\nimport android.os.Bundle;\r\nimport android.view.Menu;\r\nimport android.view.View;\r\nimport android.widget.TextView;\r\n\r\npublic class MainActivity extends Activity {\r\n    SharedPreferences sharedpreferences;\r\n    TextView name;\r\n    TextView email;\r\n    public static final String mypreference = \"mypref\";\r\n    public static final String Name = \"nameKey\";\r\n    public static final String Email = \"emailKey\";\r\n\r\n    @Override\r\n    protected void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n        setContentView(R.layout.activity_main);\r\n        name = (TextView) findViewById(R.id.etName);\r\n        email = (TextView) findViewById(R.id.etEmail);\r\n        sharedpreferences = getSharedPreferences(mypreference,\r\n                Context.MODE_PRIVATE);\r\n        if (sharedpreferences.contains(Name)) {\r\n            name.setText(sharedpreferences.getString(Name, \"\"));\r\n        }\r\n        if (sharedpreferences.contains(Email)) {\r\n            email.setText(sharedpreferences.getString(Email, \"\"));\r\n\r\n        }\r\n\r\n    }\r\n\r\n    public void Save(View view) {\r\n        String n = name.getText().toString();\r\n        String e = email.getText().toString();\r\n        SharedPreferences.Editor editor = sharedpreferences.edit();\r\n        editor.putString(Name, n);\r\n        editor.putString(Email, e);\r\n        editor.commit();\r\n    }\r\n\r\n    public void clear(View view) {\r\n        name = (TextView) findViewById(R.id.etName);\r\n        email = (TextView) findViewById(R.id.etEmail);\r\n        name.setText(\"\");\r\n        email.setText(\"\");\r\n\r\n    }\r\n\r\n    public void Get(View view) {\r\n        name = (TextView) findViewById(R.id.etName);\r\n        email = (TextView) findViewById(R.id.etEmail);\r\n        sharedpreferences = getSharedPreferences(mypreference,\r\n                Context.MODE_PRIVATE);\r\n\r\n        if (sharedpreferences.contains(Name)) {\r\n            name.setText(sharedpreferences.getString(Name, \"\"));\r\n        }\r\n        if (sharedpreferences.contains(Email)) {\r\n            email.setText(sharedpreferences.getString(Email, \"\"));\r\n\r\n        }\r\n    }\r\n\r\n    @Override\r\n    public boolean onCreateOptionsMenu(Menu menu) {\r\n        \/\/ Inflate the menu; this adds items to the action bar if it is present.\r\n        getMenuInflater().inflate(R.menu.menu_main, menu);\r\n        return true;\r\n    }\r\n\r\n}\r\n<\/code><\/pre>\n<p>&#8220;mypreference&#8221;\u662f\u7528\u4e8e\u5b58\u50a8\u5171\u4eab\u9996\u9009\u9879\u952e\u503c\u5bf9\u7684\u6587\u4ef6\u540d\u3002\u4e0b\u56fe\u5c55\u793a\u4e86\u6211\u4eec\u9879\u76ee\u7684\u6700\u7ec8\u8f93\u51fa\u6548\u679c\uff1a<\/p>\n<p>\u81f3\u6b64\uff0c\u672c\u6559\u7a0b\u7ed3\u675f\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u4e0b\u65b9\u94fe\u63a5\u4e0b\u8f7dAndroid\u5171\u4eab\u9996\u9009\u9879\u793a\u4f8b\u9879\u76ee\u3002<\/p>\n<p>\u4e0b\u8f7dAndroid\u5171\u4eab\u9996\u9009\u9879\u793a\u4f8b\u9879\u76ee\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u662f\u6587\u7ae0\u300aAndroid\u5171\u4eab\u9996\u9009\u9879\u793a\u4f8b\u6559\u7a0b\u300b\u7684\u7b2c1\u90e8\u5206\uff08\u51712\u90e8\u5206\uff09\u3002 \u5185\u5bb9\u7247\u6bb5\uff1a\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u4f7f\u7528Andr [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[900,1542,1322,1541,1543],"class_list":{"0":"post-518","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-uncategorized","7":"tag-android","9":"tag-sharedpreferences","10":"tag-1541","11":"tag-1543"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Android SharedPreferences\u5b8c\u5168\u6307\u5357\uff1a\u4ece\u5165\u95e8\u5230\u7cbe\u901a\u7684\u5171\u4eab\u9996\u9009\u9879\u6559\u7a0b - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"\u672c\u6559\u7a0b\u5168\u9762\u8bb2\u89e3Android SharedPreferences\u5171\u4eab\u9996\u9009\u9879\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u5305\u542b\u57fa\u7840\u6982\u5ff5\u3001\u5b9e\u9645\u4ee3\u7801\u793a\u4f8b\u548c\u5e38\u89c1\u95ee\u9898\u89e3\u51b3\u65b9\u6848\u3002\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u638c\u63e1Android\u8f7b\u91cf\u7ea7\u6570\u636e\u5b58\u50a8\u6280\u5de7\uff0c\u63d0\u5347\u5e94\u7528\u5f00\u53d1\u6548\u7387\u3002\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/android\u5171\u4eab\u9996\u9009\u9879\u793a\u4f8b\u6559\u7a0b\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Android SharedPreferences\u5b8c\u5168\u6307\u5357\uff1a\u4ece\u5165\u95e8\u5230\u7cbe\u901a\u7684\u5171\u4eab\u9996\u9009\u9879\u6559\u7a0b\" \/>\n<meta property=\"og:description\" content=\"\u672c\u6559\u7a0b\u5168\u9762\u8bb2\u89e3Android SharedPreferences\u5171\u4eab\u9996\u9009\u9879\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u5305\u542b\u57fa\u7840\u6982\u5ff5\u3001\u5b9e\u9645\u4ee3\u7801\u793a\u4f8b\u548c\u5e38\u89c1\u95ee\u9898\u89e3\u51b3\u65b9\u6848\u3002\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u638c\u63e1Android\u8f7b\u91cf\u7ea7\u6570\u636e\u5b58\u50a8\u6280\u5de7\uff0c\u63d0\u5347\u5e94\u7528\u5f00\u53d1\u6548\u7387\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/android\u5171\u4eab\u9996\u9009\u9879\u793a\u4f8b\u6559\u7a0b\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-06-04T15:48:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-08-02T07:20:42+00:00\" \/>\n<meta name=\"author\" content=\"\u97f5, \u79d1\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u97f5, \u79d1\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/android%e5%85%b1%e4%ba%ab%e9%a6%96%e9%80%89%e9%a1%b9%e7%a4%ba%e4%be%8b%e6%95%99%e7%a8%8b\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/android%e5%85%b1%e4%ba%ab%e9%a6%96%e9%80%89%e9%a1%b9%e7%a4%ba%e4%be%8b%e6%95%99%e7%a8%8b\/\",\"name\":\"Android SharedPreferences\u5b8c\u5168\u6307\u5357\uff1a\u4ece\u5165\u95e8\u5230\u7cbe\u901a\u7684\u5171\u4eab\u9996\u9009\u9879\u6559\u7a0b - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-06-04T15:48:29+00:00\",\"dateModified\":\"2025-08-02T07:20:42+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/6530331a63adef3b3443a1fab53a0e6e\"},\"description\":\"\u672c\u6559\u7a0b\u5168\u9762\u8bb2\u89e3Android SharedPreferences\u5171\u4eab\u9996\u9009\u9879\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u5305\u542b\u57fa\u7840\u6982\u5ff5\u3001\u5b9e\u9645\u4ee3\u7801\u793a\u4f8b\u548c\u5e38\u89c1\u95ee\u9898\u89e3\u51b3\u65b9\u6848\u3002\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u638c\u63e1Android\u8f7b\u91cf\u7ea7\u6570\u636e\u5b58\u50a8\u6280\u5de7\uff0c\u63d0\u5347\u5e94\u7528\u5f00\u53d1\u6548\u7387\u3002\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/android%e5%85%b1%e4%ba%ab%e9%a6%96%e9%80%89%e9%a1%b9%e7%a4%ba%e4%be%8b%e6%95%99%e7%a8%8b\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/android%e5%85%b1%e4%ba%ab%e9%a6%96%e9%80%89%e9%a1%b9%e7%a4%ba%e4%be%8b%e6%95%99%e7%a8%8b\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/android%e5%85%b1%e4%ba%ab%e9%a6%96%e9%80%89%e9%a1%b9%e7%a4%ba%e4%be%8b%e6%95%99%e7%a8%8b\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Android SharedPreferences\u5b8c\u5168\u6307\u5357\uff1a\u4ece\u5165\u95e8\u5230\u7cbe\u901a\u7684\u5171\u4eab\u9996\u9009\u9879\u6559\u7a0b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/6530331a63adef3b3443a1fab53a0e6e\",\"name\":\"\u97f5, \u79d1\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/429ccb39b3fff5188bc17986222cfb0936cbadb8cc933cff04ab5ca01bd30a08?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/429ccb39b3fff5188bc17986222cfb0936cbadb8cc933cff04ab5ca01bd30a08?s=96&d=mm&r=g\",\"caption\":\"\u97f5, \u79d1\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/yunke\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/android%e5%85%b1%e4%ba%ab%e9%a6%96%e9%80%89%e9%a1%b9%e7%a4%ba%e4%be%8b%e6%95%99%e7%a8%8b\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Android SharedPreferences\u5b8c\u5168\u6307\u5357\uff1a\u4ece\u5165\u95e8\u5230\u7cbe\u901a\u7684\u5171\u4eab\u9996\u9009\u9879\u6559\u7a0b - Blog - Silicon Cloud","description":"\u672c\u6559\u7a0b\u5168\u9762\u8bb2\u89e3Android SharedPreferences\u5171\u4eab\u9996\u9009\u9879\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u5305\u542b\u57fa\u7840\u6982\u5ff5\u3001\u5b9e\u9645\u4ee3\u7801\u793a\u4f8b\u548c\u5e38\u89c1\u95ee\u9898\u89e3\u51b3\u65b9\u6848\u3002\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u638c\u63e1Android\u8f7b\u91cf\u7ea7\u6570\u636e\u5b58\u50a8\u6280\u5de7\uff0c\u63d0\u5347\u5e94\u7528\u5f00\u53d1\u6548\u7387\u3002","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/android\u5171\u4eab\u9996\u9009\u9879\u793a\u4f8b\u6559\u7a0b\/","og_locale":"zh_CN","og_type":"article","og_title":"Android SharedPreferences\u5b8c\u5168\u6307\u5357\uff1a\u4ece\u5165\u95e8\u5230\u7cbe\u901a\u7684\u5171\u4eab\u9996\u9009\u9879\u6559\u7a0b","og_description":"\u672c\u6559\u7a0b\u5168\u9762\u8bb2\u89e3Android SharedPreferences\u5171\u4eab\u9996\u9009\u9879\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u5305\u542b\u57fa\u7840\u6982\u5ff5\u3001\u5b9e\u9645\u4ee3\u7801\u793a\u4f8b\u548c\u5e38\u89c1\u95ee\u9898\u89e3\u51b3\u65b9\u6848\u3002\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u638c\u63e1Android\u8f7b\u91cf\u7ea7\u6570\u636e\u5b58\u50a8\u6280\u5de7\uff0c\u63d0\u5347\u5e94\u7528\u5f00\u53d1\u6548\u7387\u3002","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/android\u5171\u4eab\u9996\u9009\u9879\u793a\u4f8b\u6559\u7a0b\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-06-04T15:48:29+00:00","article_modified_time":"2025-08-02T07:20:42+00:00","author":"\u97f5, \u79d1","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u97f5, \u79d1","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/android%e5%85%b1%e4%ba%ab%e9%a6%96%e9%80%89%e9%a1%b9%e7%a4%ba%e4%be%8b%e6%95%99%e7%a8%8b\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/android%e5%85%b1%e4%ba%ab%e9%a6%96%e9%80%89%e9%a1%b9%e7%a4%ba%e4%be%8b%e6%95%99%e7%a8%8b\/","name":"Android SharedPreferences\u5b8c\u5168\u6307\u5357\uff1a\u4ece\u5165\u95e8\u5230\u7cbe\u901a\u7684\u5171\u4eab\u9996\u9009\u9879\u6559\u7a0b - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-06-04T15:48:29+00:00","dateModified":"2025-08-02T07:20:42+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/6530331a63adef3b3443a1fab53a0e6e"},"description":"\u672c\u6559\u7a0b\u5168\u9762\u8bb2\u89e3Android SharedPreferences\u5171\u4eab\u9996\u9009\u9879\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u5305\u542b\u57fa\u7840\u6982\u5ff5\u3001\u5b9e\u9645\u4ee3\u7801\u793a\u4f8b\u548c\u5e38\u89c1\u95ee\u9898\u89e3\u51b3\u65b9\u6848\u3002\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u638c\u63e1Android\u8f7b\u91cf\u7ea7\u6570\u636e\u5b58\u50a8\u6280\u5de7\uff0c\u63d0\u5347\u5e94\u7528\u5f00\u53d1\u6548\u7387\u3002","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/android%e5%85%b1%e4%ba%ab%e9%a6%96%e9%80%89%e9%a1%b9%e7%a4%ba%e4%be%8b%e6%95%99%e7%a8%8b\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/android%e5%85%b1%e4%ba%ab%e9%a6%96%e9%80%89%e9%a1%b9%e7%a4%ba%e4%be%8b%e6%95%99%e7%a8%8b\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/android%e5%85%b1%e4%ba%ab%e9%a6%96%e9%80%89%e9%a1%b9%e7%a4%ba%e4%be%8b%e6%95%99%e7%a8%8b\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"Android SharedPreferences\u5b8c\u5168\u6307\u5357\uff1a\u4ece\u5165\u95e8\u5230\u7cbe\u901a\u7684\u5171\u4eab\u9996\u9009\u9879\u6559\u7a0b"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/6530331a63adef3b3443a1fab53a0e6e","name":"\u97f5, \u79d1","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/429ccb39b3fff5188bc17986222cfb0936cbadb8cc933cff04ab5ca01bd30a08?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/429ccb39b3fff5188bc17986222cfb0936cbadb8cc933cff04ab5ca01bd30a08?s=96&d=mm&r=g","caption":"\u97f5, \u79d1"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/yunke\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/android%e5%85%b1%e4%ba%ab%e9%a6%96%e9%80%89%e9%a1%b9%e7%a4%ba%e4%be%8b%e6%95%99%e7%a8%8b\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/518","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=518"}],"version-history":[{"count":4,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/518\/revisions"}],"predecessor-version":[{"id":110189,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/518\/revisions\/110189"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=518"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=518"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=518"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}