{"id":3057,"date":"2020-12-25T11:00:06","date_gmt":"2020-12-25T03:00:06","guid":{"rendered":"https:\/\/learn-house.idv.tw\/?p=3057"},"modified":"2020-12-25T11:05:29","modified_gmt":"2020-12-25T03:05:29","slug":"android%e9%80%8f%e9%81%8eparcelable%e5%9c%a8activity%e9%96%93%e5%82%b3%e9%81%9earraylist%e7%89%a9%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/learn-house.idv.tw\/?p=3057","title":{"rendered":"[Android]\u900f\u904eParcelable\u5728Activity\u9593\u50b3\u905eArrayList\u7269\u4ef6"},"content":{"rendered":"<p>Android\u958b\u767c\u4eba\u54e1\u90fd\u77e5\u8981\u50b3\u905e\u7269\u4ef6\u7d66Activity\uff0c\u4e0d\u80fd\u76f4\u63a5\u5beb\u4e00\u500bpublic\u7684function\u4f86set\u8cc7\u6599<br \/>\n\u800c\u8981\u900f\u904eintent\u4f86\u593e\u5e36\u50b3\u905e\u7684\u8a0a\u606f\uff0c\u80fd\u50b3\u905e\u7684\u8cc7\u6599\u578b\u614b\u53c8\u4e0d\u80fd\u662f\u81ea\u5df1\u5b9a\u7fa9\u7684object<br \/>\n\u5225\u8aaa\u81ea\u5df1\u5b9a\u7fa9\u7684\u4e86\uff0c\u5c31\u9023ArrayList\uff0c\u4e5f\u7121\u6cd5\u96a8\u610f\u7684\u585e\u9032\u53bbintent\u4f86\u50b3\u905e<br \/>\n\u53ea\u80fd\u662f\u4ee5\u4e0b\u5e7e\u7a2e\uff1a<br \/>\n<!--more--><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nIntent \tputExtra(String name, String&#x5B;] value)\r\nIntent \tputExtra(String name, Parcelable value)\r\nIntent \tputExtra(String name, long value)\r\nIntent \tputExtra(String name, boolean value)\r\nIntent \tputExtra(String name, double value)\r\nIntent \tputExtra(String name, Parcelable&#x5B;] value)\r\nIntent \tputExtra(String name, char value)\r\nIntent \tputExtra(String name, int&#x5B;] value)\r\nIntent \tputExtra(String name, int value)\r\nIntent \tputExtra(String name, double&#x5B;] value)\t \t \t \t\r\nIntent \tputExtra(String name, short value) \t \t \t \t \t\r\nIntent \tputExtra(String name, long&#x5B;] value) \t \t \t \t \t\r\nIntent \tputExtra(String name, boolean&#x5B;] value) \t \t \t \t \t\r\nIntent \tputExtra(String name, short&#x5B;] value) \t \t \t \t \t\r\nIntent \tputExtra(String name, String value) \t \t \t \t \t\r\nIntent \tputExtra(String name, Serializable value) \t \t \t \t \t\r\nIntent \tputExtra(String name, float&#x5B;] value) \t \t \t \t \t\r\nIntent \tputExtra(String name, Bundle value) \t \t \t \t \t\r\nIntent \tputExtra(String name, byte&#x5B;] value) \t \t \t \t \t\r\nIntent \tputExtra(String name, CharSequence value) \t \t \t \t \t\r\nIntent \tputExtra(String name, char&#x5B;] value) \t \t \t \t \t\r\nIntent \tputExtra(String name, byte value)\r\n<\/pre>\n<p>\u56e0\u6b64\u5982\u679c\u8981\u7528ArrayList\u4f86\u50b3\u905e\u7269\u4ef6\uff0c\u5247\u9700\u5148\u5c07\u8981\u50b3\u905e\u7684\u7269\u4ef6\u8f49\u6210Parcelable<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nimport android.os.Parcel;\r\nimport android.os.Parcelable;\r\n\r\npublic class Module implements Parcelable {\r\n\tprivate String name;\r\n\tprivate String version;\r\n\tprivate String url;\r\n\tprivate String checksum;\r\n\tprivate String size;\r\n\r\n\tpublic Module() {\r\n\t}\r\n\t\r\n\tpublic void setName(String name) {\r\n\t    this.name = name;\r\n\t}\r\n\r\n\tpublic String getName() {\r\n\t    return name;\r\n\t}\r\n\t\r\n\tpublic void setVersion(String version) {\r\n\t    this.version = version;\r\n\t}\r\n\r\n\tpublic String getVersion() {\r\n\t    return version;\r\n\t}\r\n\t\r\n\tpublic void setURL(String url) {\r\n\t    this.url = url;\r\n\t}\r\n\r\n\tpublic String getURL() {\r\n\t    return url;\r\n\t}\r\n\t\r\n\tpublic void setChecksum(String checksum) {\r\n\t    this.checksum = checksum;\r\n\t}\r\n\r\n\tpublic String getChecksum() {\r\n\t    return checksum;\r\n\t}\r\n\t\r\n\tpublic void setSize(String size) {\r\n\t    this.size = size;\r\n\t}\r\n\r\n\tpublic String getSize() {\r\n\t    return size;\r\n\t}\r\n\r\n\t@Override\r\n\tpublic int describeContents() {\r\n\t\treturn 0;\r\n\t}\r\n\r\n\t@Override\r\n\tpublic void writeToParcel(Parcel out, int flags)\r\n\t{\r\n\t\tout.writeString(name);\r\n\t\tout.writeString(version);\r\n\t\tout.writeString(url);\r\n\t\tout.writeString(checksum);\r\n\t\tout.writeString(size);\r\n\t}\r\n\r\n\tpublic static final Parcelable.Creator&lt;Module&gt; CREATOR = new Creator&lt;Module&gt;() {\r\n\t\t@Override\r\n\t\tpublic Module&#x5B;] newArray(int size) {\r\n\t\t\treturn new Module&#x5B;size];\r\n\t\t}\r\n\r\n\t\t@Override\r\n\t\tpublic Module createFromParcel(Parcel in) {\r\n\t\t\treturn new Module(in);\r\n\t\t}\r\n\t};\r\n\r\n\tpublic Module(Parcel in) {\r\n\t\tname = in.readString();\r\n\t\tversion = in.readString();\r\n\t\turl = in.readString();\r\n\t\tchecksum = in.readString();\r\n\t\tsize = in.readString();\r\n\t}\r\n}\r\n<\/pre>\n<p>\u50b3\u905e\u7aef\uff1a<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nArrayList&lt;Module&gt; updateList;\r\nModule module = new Module();\r\nmodule.setName(&quot;aaa&quot;);\r\n...(\u7565)\r\nupdateList.add(module);\r\n\r\nIntent intent = new Intent(context, TargetActivity.class);\r\nintent.putParcelableArrayListExtra(&quot;updateList&quot;, updateList);\r\nstartActivity(intent);\r\n<\/pre>\n<p>Activity\u63a5\u6536\u7aef\uff1a<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nArrayList&lt;Module&gt; updateList = getIntent().getParcelableArrayListExtra(&quot;updateList&quot;);\r\nfor (int i=0; i&lt;updateList.size(); i++) {\r\n    Module module = (Module) updateList.get(i);\r\n\t...(\u7565)\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Android\u958b\u767c\u4eba\u54e1\u90fd\u77e5\u8981\u50b3\u905e\u7269\u4ef6\u7d66Activity\uff0c\u4e0d\u80fd\u76f4\u63a5\u5beb\u4e00\u500bpublic\u7684function\u4f86set\u8cc7 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-3057","post","type-post","status-publish","format-standard","hentry","category-5"],"_links":{"self":[{"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/3057"}],"collection":[{"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3057"}],"version-history":[{"count":0,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/3057\/revisions"}],"wp:attachment":[{"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3057"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3057"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3057"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}