{"id":307045,"date":"2024-05-20T20:25:38","date_gmt":"2024-05-20T12:25:38","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/307045.html"},"modified":"2024-05-20T20:25:55","modified_gmt":"2024-05-20T12:25:55","slug":"android-%e7%a8%8b%e5%ba%8f%e4%b8%ad%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0-activity-%e4%b9%8b%e9%97%b4%e7%9a%84%e6%95%b0%e6%8d%ae%e4%bc%a0%e9%80%92","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/307045.html","title":{"rendered":"Android \u7a0b\u5e8f\u4e2d\u5982\u4f55\u5b9e\u73b0 Activity \u4e4b\u95f4\u7684\u6570\u636e\u4f20\u9012"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/26223416\/006f1a90-de29-4223-8ff4-2483e9091d64.webp\" alt=\"Android \u7a0b\u5e8f\u4e2d\u5982\u4f55\u5b9e\u73b0 Activity \u4e4b\u95f4\u7684\u6570\u636e\u4f20\u9012\" \/><\/p>\n<p><h2>\u4e00\u3001\u76f4\u63a5\u4f7f\u7528 Intent \u4f20\u9012<\/h2>\n<\/p>\n<p><p><strong>Android \u5e94\u7528\u4e2d\u5b9e\u73b0 Activity \u4e4b\u95f4\u7684\u6570\u636e\u4f20\u9012\u4e3b\u8981\u4f9d\u8d56\u4e8e Intent \u5bf9\u8c61<\/strong>\uff0c\u8be5\u5bf9\u8c61\u4e0d\u4ec5\u80fd\u591f\u542f\u52a8\u76ee\u6807 Activity\uff0c\u8fd8\u80fd\u591f\u643a\u5e26\u7b80\u5355\u6570\u636e\u7c7b\u578b\uff08\u5982String\u3001int\u7b49\uff09\u6216\u8005\u53ef\u5e8f\u5217\u5316\uff08Serializable\uff09\/\u5e73\u884c\u5316\uff08Parcelable\uff09\u5bf9\u8c61\u8fdb\u884c\u6570\u636e\u4f20\u8f93\u3002<strong>Intent \u4f20\u9012\u6570\u636e\u7b80\u5355\u4e14\u9ad8\u6548<\/strong>\uff0c\u662f\u6700\u5e38\u7528\u7684\u6570\u636e\u4f20\u9012\u65b9\u5f0f\u4e4b\u4e00\u3002<\/p>\n<\/p>\n<p><p>\u8981\u4f7f\u7528 Intent \u4f20\u9012\u6570\u636e\uff0c\u9996\u5148\u5728\u6e90 Activity \u4e2d\u521b\u5efa Intent \u5bf9\u8c61\uff0c\u4f7f\u7528 <code>putExtra<\/code> \u65b9\u6cd5\u6dfb\u52a0\u9700\u8981\u4f20\u9012\u7684\u6570\u636e\uff0c\u7136\u540e\u542f\u52a8\u76ee\u6807 Activity\u3002\u5728\u76ee\u6807 Activity \u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7 <code>getIntent<\/code> \u65b9\u6cd5\u83b7\u53d6\u5230\u4f20\u9012\u7684\u6570\u636e\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><p>\u6e90 Activity:<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">Intent intent = new Intent(SourceActivity.this, TargetActivity.class);<\/p>\n<p>intent.putExtra(&quot;key&quot;, &quot;value&quot;);<\/p>\n<p>startActivity(intent);<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u76ee\u6807 Activity:<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">Intent intent = getIntent();<\/p>\n<p>String value = intent.getStringExtra(&quot;key&quot;);<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6b64\u5916\uff0cIntent \u4e5f\u652f\u6301\u542f\u52a8 Service \u6216\u8005\u53d1\u9001 Broadcast\uff0c\u5e76\u643a\u5e26\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h2>\u4e8c\u3001\u4f7f\u7528 Bundle \u4f20\u9012\u590d\u6742\u6570\u636e\u7c7b\u578b<\/h2>\n<\/p>\n<p><p>\u5728\u9700\u8981\u4f20\u9012\u66f4\u4e3a\u590d\u6742\u7684\u6570\u636e\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528 Bundle \u5bf9\u8c61\u3002<strong>Bundle \u7c7b\u4f3c\u4e8e\u4e00\u4e2a\u5b58\u50a8\u952e\u503c\u5bf9\u7684\u5bb9\u5668<\/strong>\uff0c\u80fd\u591f\u5728\u4e0d\u540c\u7684 Activity \u4e4b\u95f4\u4f20\u9012\u591a\u79cd\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<\/p>\n<p><p>\u5c06\u6570\u636e\u6dfb\u52a0\u5230 Bundle \u4e2d\uff0c\u7136\u540e\u901a\u8fc7 Intent \u4f20\u9012\u8be5 Bundle\uff1a<\/p>\n<\/p>\n<p><p>\u6e90 Activity:<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">Bundle bundle = new Bundle();<\/p>\n<p>bundle.putString(&quot;key&quot;, &quot;value&quot;);<\/p>\n<p>Intent intent = new Intent(SourceActivity.this, TargetActivity.class);<\/p>\n<p>intent.putExtras(bundle);<\/p>\n<p>startActivity(intent);<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u76ee\u6807 Activity:<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">Intent intent = getIntent();<\/p>\n<p>Bundle bundle = intent.getExtras();<\/p>\n<p>if(bundle != null){<\/p>\n<p>    String value = bundle.getString(&quot;key&quot;);<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e09\u3001\u4f7f\u7528 startActivityForResult \u8fdb\u884c\u4ea4\u4e92<\/h2>\n<\/p>\n<p><p>\u5f53\u4e00\u4e2a Activity \u9700\u8981\u4ece\u53e6\u4e00\u4e2a Activity \u83b7\u53d6\u8fd4\u56de\u7ed3\u679c\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>startActivityForResult<\/code> \u65b9\u6cd5\u3002\u5728\u76ee\u6807 Activity \u5b8c\u6210\u64cd\u4f5c\u540e\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u7ed3\u679c\u5e76\u8fd4\u56de\u5230\u6e90 Activity\u3002<\/p>\n<\/p>\n<p><p>\u6e90 Activity \u542f\u52a8\u76ee\u6807 Activity:<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">Intent intent = new Intent(SourceActivity.this, TargetActivity.class);<\/p>\n<p>startActivityForResult(intent, REQUEST_CODE);<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u76ee\u6807 Activity \u4e2d\u8bbe\u7f6e\u8fd4\u56de\u6570\u636e:<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">Intent returnIntent = new Intent();<\/p>\n<p>returnIntent.putExtra(&quot;result_key&quot;, &quot;result_value&quot;);<\/p>\n<p>setResult(Activity.RESULT_OK, returnIntent);<\/p>\n<p>finish();<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6e90 Activity \u901a\u8fc7\u91cd\u5199 <code>onActivityResult<\/code> \u65b9\u6cd5\u6765\u63a5\u6536\u7ed3\u679c:<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">@Override<\/p>\n<p>protected void onActivityResult(int requestCode, int resultCode, Intent data) {<\/p>\n<p>    super.onActivityResult(requestCode, resultCode, data);<\/p>\n<p>    if(requestCode == REQUEST_CODE &amp;&amp; resultCode == Activity.RESULT_OK){<\/p>\n<p>        String result = data.getStringExtra(&quot;result_key&quot;);<\/p>\n<p>        \/\/ \u5904\u7406\u8fd4\u56de\u7684\u7ed3\u679c<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u56db\u3001\u901a\u8fc7 Singleton \u7c7b\u6216\u9759\u6001\u53d8\u91cf\u4f20\u9012<\/h2>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528\u5e94\u7528\u7ea7\u7684 Singleton \u7c7b\u6216\u9759\u6001\u53d8\u91cf\u5728\u591a\u4e2a Activity \u4e4b\u95f4\u5171\u4eab\u6570\u636e\u3002\u8fd9\u79cd\u65b9\u5f0f\u8981\u614e\u7528\uff0c\u56e0\u4e3a\u592a\u591a\u7684\u5168\u5c40\u53d8\u91cf\u6216\u5355\u4f8b\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5185\u5b58\u6cc4\u9732\u7684\u98ce\u9669\u3002<\/p>\n<\/p>\n<p><p>\u5728 Singleton \u7c7b\u4e2d\u4fdd\u5b58\u6570\u636e\uff0c\u4f8b\u5982:<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">public class DataHolder {<\/p>\n<p>    private static final DataHolder instance = new DataHolder();<\/p>\n<p>    private String data;<\/p>\n<p>    public static DataHolder getInstance() {<\/p>\n<p>        return instance;<\/p>\n<p>    }<\/p>\n<p>    public String getData() {<\/p>\n<p>        return data;<\/p>\n<p>    }<\/p>\n<p>    public void setData(String data) {<\/p>\n<p>        this.data = data;<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6e90 Activity:<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">DataHolder.getInstance().setData(&quot;Some Data&quot;);<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u76ee\u6807 Activity:<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">String data = DataHolder.getInstance().getData();<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e94\u3001\u4f7f\u7528 Content Provider \u6216 Shared Preferences<\/h2>\n<\/p>\n<p><p>\u5982\u679c\u9700\u8981\u5728\u591a\u4e2a\u5e94\u7528\u95f4\u6216\u8005 Activity \u95f4\u6301\u4e45\u5316\u5730\u5171\u4eab\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528 Content Provider \u6216\u8005 Shared Preferences\u3002<\/p>\n<\/p>\n<p><p><strong>Content Provider<\/strong> \u63d0\u4f9b\u4e86\u4e00\u79cd\u5728\u4e0d\u540c\u5e94\u7528\u95f4\u5171\u4eab\u6570\u636e\u7684\u6807\u51c6\u63a5\u53e3\u3002\u901a\u8fc7 Content Provider\uff0c\u4e00\u4e2a\u5e94\u7528\u80fd\u591f\u5bf9\u5916\u5171\u4eab\u5176\u6570\u636e\u7ed9\u53e6\u5916\u7684\u5e94\u7528\u8bbf\u95ee\u548c\u4fee\u6539\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">\/\/ \u63d2\u5165\u6216\u67e5\u8be2\u6570\u636e\u4f7f\u7528\u5bf9\u5e94\u7684 ContentResolver \u65b9\u6cd5<\/p>\n<p>getContentResolver().query();<\/p>\n<p>getContentResolver().insert();<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>Shared Preferences<\/strong> \u63d0\u4f9b\u4e86\u4e00\u79cd\u8f7b\u91cf\u7ea7\u7684\u5b58\u50a8\u65b9\u5f0f\uff0c\u9002\u7528\u4e8e\u4fdd\u5b58\u7b80\u5355\u7684\u6570\u636e\u683c\u5f0f\uff0c\u5982\u952e\u503c\u5bf9\u3002<\/p>\n<\/p>\n<p><p>\u4fdd\u5b58\u6570\u636e\u5230 Shared Preferences:<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">SharedPreferences sharedPreferences = getSharedPreferences(&quot;MyPrefs&quot;, Context.MODE_PRIVATE);<\/p>\n<p>SharedPreferences.Editor editor = sharedPreferences.edit();<\/p>\n<p>editor.putString(&quot;key&quot;, &quot;value&quot;);<\/p>\n<p>editor.commit();<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4ece Shared Preferences \u83b7\u53d6\u6570\u636e:<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">SharedPreferences sharedPreferences = getSharedPreferences(&quot;MyPrefs&quot;, Context.MODE_PRIVATE);<\/p>\n<p>String value = sharedPreferences.getString(&quot;key&quot;, &quot;default_value&quot;);<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u516d\u3001\u4f7f\u7528\u6570\u636e\u5e93 SQLite<\/h2>\n<\/p>\n<p><p>\u5f53\u9700\u8981\u5b58\u50a8\u7ed3\u6784\u5316\u6570\u636e\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528 SQLite \u6570\u636e\u5e93\u3002\u5728 Android \u4e2d\uff0cSQLite \u662f\u4e00\u79cd\u8f7b\u91cf\u7ea7\u7684\u6570\u636e\u5e93\u7cfb\u7edf\uff0c\u5b83\u5141\u8bb8\u6211\u4eec\u5728\u672c\u5730\u8bbe\u5907\u4e0a\u5b58\u50a8\u548c\u7ba1\u7406\u6570\u636e\u3002<\/p>\n<\/p>\n<p><p>\u521b\u5efa\u6570\u636e\u5e93\u548c\u8868\uff0c\u7136\u540e\u8fdb\u884c\u6570\u636e\u7684\u589e\u5220\u6539\u67e5\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u5728\u6e90 Activity \u4e2d\u63d2\u5165\u6570\u636e\uff0c\u5728\u76ee\u6807 Activity \u4e2d\u67e5\u8be2\u6570\u636e\u3002SQLite \u901a\u8fc7 SQLiteOpenHelper \u7c7b\u548c SQLiteDatabase \u7c7b\u63d0\u4f9b\u7ba1\u7406\u548c\u64cd\u4f5c\u6570\u636e\u5e93\u7684\u5404\u79cd\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h2>\u4e03\u3001\u4f7f\u7528\u5168\u5c40 Application \u7c7b<\/h2>\n<\/p>\n<p><p>\u7ee7\u627f <code>Application<\/code> \u7c7b\u5e76\u5728\u5176\u4e2d\u52a0\u5165\u5168\u5c40\u6570\u636e\u5b58\u50a8\u7684\u903b\u8f91\u3002\u8fd9\u4e2a\u81ea\u5b9a\u4e49\u7684\u5e94\u7528\u7c7b\u4f1a\u5728\u6240\u6709\u7684 Activity \u4e4b\u524d\u88ab\u521b\u5efa\uff0c\u56e0\u6b64\u5728\u5b83\u91cc\u9762\u5b58\u50a8\u7684\u6570\u636e\u53ef\u4ee5\u5728\u6240\u6709\u7684 Activity \u4e2d\u88ab\u8bbf\u95ee\u3002<\/p>\n<\/p>\n<p><p>\u81ea\u5b9a\u4e49 Application \u7c7b:<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">public class MyApp extends Application {<\/p>\n<p>    private String globalData;<\/p>\n<p>    public String getGlobalData() {<\/p>\n<p>        return globalData;<\/p>\n<p>    }<\/p>\n<p>    public void setGlobalData(String globalData) {<\/p>\n<p>        this.globalData = globalData;<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u6e90 Activity \u4e2d:<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">((MyApp) getApplication()).setGlobalData(&quot;Shared Data&quot;);<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u76ee\u6807 Activity \u4e2d:<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">String data = ((MyApp) getApplication()).getGlobalData();<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b9e\u73b0 Activity \u4e4b\u95f4\u7684\u6570\u636e\u4f20\u9012\u6709\u5f88\u591a\u79cd\u65b9\u5f0f\uff0c\u9009\u62e9\u6700\u9002\u5408\u7684\u65b9\u5f0f\u53d6\u51b3\u4e8e\u5e94\u7528\u7684\u9700\u6c42\u548c\u6570\u636e\u7c7b\u578b\u7684\u590d\u6742\u7a0b\u5ea6\u3002\u5f00\u53d1\u8005\u9700\u8981\u6839\u636e\u5177\u4f53\u60c5\u51b5\u505a\u51fa\u9009\u62e9\uff0c\u4ee5\u786e\u4fdd\u6570\u636e\u4f20\u9012\u9ad8\u6548\u4e14\u5b89\u5168\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1. \u5728 Android \u7a0b\u5e8f\u4e2d\uff0c\u5982\u4f55\u5728 Activity \u4e4b\u95f4\u4f20\u9012\u6570\u636e\uff1f<\/strong><\/p>\n<p>Android \u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u5f0f\u6765\u5b9e\u73b0 Activity \u4e4b\u95f4\u7684\u6570\u636e\u4f20\u9012\u3002\u4e00\u79cd\u5e38\u7528\u7684\u65b9\u5f0f\u662f\u4f7f\u7528 Intent \u5bf9\u8c61\u6765\u4f20\u9012\u6570\u636e\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u5728\u53d1\u9001 Intent \u65f6\uff0c\u8c03\u7528 <code>putExtra()<\/code> \u65b9\u6cd5\u6765\u5c06\u6570\u636e\u5b58\u50a8\u5728 Intent \u5bf9\u8c61\u4e2d\uff0c\u7136\u540e\u5728\u63a5\u6536 Intent \u65f6\uff0c\u4f7f\u7528\u5bf9\u5e94\u7684 <code>getExtra()<\/code> \u65b9\u6cd5\u6765\u83b7\u53d6\u6570\u636e\u3002\u53e6\u5916\uff0c\u4f60\u8fd8\u53ef\u4ee5\u4f7f\u7528 Bundle \u5bf9\u8c61\u6765\u4f20\u9012\u590d\u6742\u7684\u6570\u636e\u7c7b\u578b\uff0c\u4f8b\u5982\u6570\u7ec4\u6216\u5bf9\u8c61\u3002<\/p>\n<p><strong>2. \u5982\u4f55\u5728\u4e24\u4e2a Fragment \u4e4b\u95f4\u4f20\u9012\u6570\u636e\uff1f<\/strong><\/p>\n<p>\u5728\u4e24\u4e2a Fragment \u4e4b\u95f4\u4f20\u9012\u6570\u636e\u4e5f\u53ef\u4ee5\u4f7f\u7528 Intent \u6216\u8005 Bundle \u5bf9\u8c61\u3002\u4f60\u53ef\u4ee5\u5728\u4e00\u4e2a Fragment \u7684\u4ee3\u7801\u4e2d\uff0c\u901a\u8fc7\u83b7\u53d6 Activity \u7684\u5f15\u7528\u6765\u521b\u5efa\u4e00\u4e2a Intent \u5bf9\u8c61\uff0c\u5e76\u4f7f\u7528 <code>putExtra()<\/code> \u65b9\u6cd5\u6765\u5b58\u50a8\u9700\u8981\u4f20\u9012\u7684\u6570\u636e\u3002\u7136\u540e\uff0c\u5728\u53e6\u4e00\u4e2a Fragment \u4e2d\uff0c\u4f7f\u7528 <code>getActivity()<\/code> \u65b9\u6cd5\u83b7\u53d6\u6240\u5173\u8054\u7684 Activity\uff0c\u5728\u8be5 Activity \u4e2d\u83b7\u53d6 Intent \u7684\u6570\u636e\u3002<\/p>\n<p>\u53e6\u5916\uff0c\u5982\u679c\u4e24\u4e2a Fragment \u5728\u540c\u4e00\u4e2a Activity \u4e2d\uff0c\u4f60\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5171\u4eab ViewModel \u6765\u5b9e\u73b0\u6570\u636e\u5171\u4eab\u3002\u901a\u8fc7\u521b\u5efa\u4e00\u4e2a ViewModel\uff0c\u7136\u540e\u5728\u4e24\u4e2a Fragment \u4e2d\u83b7\u53d6\u8be5 ViewModel \u7684\u5f15\u7528\uff0c\u5c31\u53ef\u4ee5\u5171\u4eab\u6570\u636e\u4e86\u3002<\/p>\n<p><strong>3. \u5728 Android \u7a0b\u5e8f\u4e2d\uff0c\u5982\u4f55\u5728 Activity \u4e4b\u95f4\u4f20\u9012\u5bf9\u8c61\uff1f<\/strong><\/p>\n<p>\u5728 Activity \u4e4b\u95f4\u4f20\u9012\u5bf9\u8c61\u65f6\uff0c\u4e00\u79cd\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u4f7f\u5bf9\u8c61\u5b9e\u73b0 Parcelable \u63a5\u53e3\u3002Parcelable \u63a5\u53e3\u4f7f\u5f97\u5bf9\u8c61\u80fd\u591f\u5728\u8fdb\u7a0b\u95f4\u4f20\u8f93\uff0c\u5e76\u4e14\u6bd4 Serializable \u63a5\u53e3\u66f4\u9ad8\u6548\u3002\u4f60\u53ea\u9700\u8981\u5728\u5bf9\u8c61\u7684\u7c7b\u4e2d\u5b9e\u73b0 Parcelable \u63a5\u53e3\uff0c\u5e76\u4e14\u5b9e\u73b0\u76f8\u5e94\u7684 <code>writeToParcel()<\/code> \u548c <code>createFromParcel()<\/code> \u65b9\u6cd5\u3002<\/p>\n<p>\u5728\u53d1\u9001 Intent \u65f6\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 <code>putExtra()<\/code> \u65b9\u6cd5\u4f20\u9012 Parcelable \u5bf9\u8c61\uff0c\u5e76\u5728\u63a5\u6536 Intent \u65f6\uff0c\u4f7f\u7528 <code>getParcelableExtra()<\/code> \u65b9\u6cd5\u83b7\u53d6\u5bf9\u8c61\u3002<\/p>\n<p>\u53e6\u5916\uff0c\u5982\u679c\u4f60\u4f7f\u7528\u7684\u662f Fragment \u6765\u4f20\u9012\u5bf9\u8c61\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5\u5728 Bundle \u5bf9\u8c61\u4e2d\u5b58\u50a8\u5bf9\u8c61\u3002\u5728\u53d1\u9001 Fragment \u4e4b\u95f4\u7684\u6570\u636e\u65f6\uff0c\u4f7f\u7528 <code>setArguments()<\/code> \u65b9\u6cd5\u5c06 Bundle \u5bf9\u8c61\u4f20\u9012\u7ed9 Fragment\uff0c\u7136\u540e\u5728\u63a5\u6536 Fragment \u4e2d\u901a\u8fc7 <code>getArguments()<\/code> \u65b9\u6cd5\u83b7\u53d6 Bundle \u5bf9\u8c61\uff0c\u518d\u4ece\u4e2d\u83b7\u53d6\u5bf9\u8c61\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4e00\u3001\u76f4\u63a5\u4f7f\u7528 Intent \u4f20\u9012 Android \u5e94\u7528\u4e2d\u5b9e\u73b0 Activity \u4e4b\u95f4\u7684\u6570\u636e\u4f20\u9012\u4e3b\u8981\u4f9d\u8d56\u4e8e In [&hellip;]","protected":false},"author":3,"featured_media":307063,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/307045"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=307045"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/307045\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/307063"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=307045"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=307045"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=307045"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}