{"id":576,"date":"2020-06-17T14:42:02","date_gmt":"2020-06-17T06:42:02","guid":{"rendered":"https:\/\/badgameshow.com\/fly\/?p=576"},"modified":"2020-06-17T14:42:24","modified_gmt":"2020-06-17T06:42:24","slug":"android-implement-kotlin-parcelable","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/fly\/android-implement-kotlin-parcelable\/","title":{"rendered":"Android implement Kotlin Parcelable"},"content":{"rendered":"<h3>1.\u5275\u5efa\u4e00\u500bModle,\u5be6\u73feParcelable\u4e26\u5728\u985e\u524d\u9762\u6dfb\u52a0@Parcelize\u8a3b\u91cb<\/h3>\n<pre><code class=\"language-Kotlin line-numbers\">@Parcelize\ndata class Student(val name: String, val age: Int) : Parcelable\n<\/code><\/pre>\n<h3>2.\u5229\u7528intent\u50b3\u503c\u5230\u53e6\u4e00\u500b\u9801\u9762<\/h3>\n<pre><code class=\"language-Kotlin line-numbers\">val tomStudent = Student(\"Tom\", 15)\nval tonyStudnet = Student(\"Tony\", 11)\nval amyStudent = Student(\"Amy\", 17)\n\nval intent = Intent(this, TwoActivity::class.java)\nintent.putExtra(\"students\", arrayListOf(tomStudent, amyStudent, tonyStudnet))\nstartActivity(intent)\n<\/code><\/pre>\n<h3>3.\u53e6\u4e00\u500b\u9801\u9762\u53d6\u5f97Model\u7269\u4ef6<\/h3>\n<pre><code class=\"language-Kotlin line-numbers\">val students = intent.getParcelableArrayListExtra&lt;Student&gt;(\"students\")\n\nstudents?.run {\n     indices.forEach {\n         Log.d(\"name\", students[it].name)\n         Log.d(\"age\", students[it].age.toString())\n     }\n}\n<\/code><\/pre>\n\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>1.\u5275\u5efa\u4e00\u500bModle,\u5be6\u73feParcelable\u4e26\u5728\u985e\u524d\u9762\u6dfb\u52a0@Parcelize\u8a3b\u91cb @Parcelize  &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"pgc_sgb_lightbox_settings":"","footnotes":""},"categories":[5],"tags":[13,15,88],"class_list":["post-576","post","type-post","status-publish","format-standard","hentry","category-android","tag-android","tag-kotlin","tag-parcelable"],"_links":{"self":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/576","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/comments?post=576"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/576\/revisions"}],"predecessor-version":[{"id":577,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/576\/revisions\/577"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/media?parent=576"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/categories?post=576"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/tags?post=576"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}