日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

Intent 传递对象

發(fā)布時(shí)間:2025/5/22 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Intent 传递对象 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

方法:

可以讓這個(gè)要傳遞的對(duì)象所屬類實(shí)現(xiàn)Serializable或者Parcelable接口,

然后利用onCreate函數(shù)中的Bundle參數(shù)作為載體,傳遞這個(gè)對(duì)象。

例如:

<span style="font-size:14px;color: rgb(75, 75, 75);">@Override public void onItemClick(AdapterView<?> parent, View view, int position, long i) { User user= (User) Connect.getUser(position); Intent intent = new Intent(Activity1.this,Activity2.class); Bundle bundle = new Bundle(); bundle.putSerializable("USER", user); intent.putExtras(bundle); startActivity(intent); } }在接收對(duì)象的地方:protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.detail); User </span><span style="color: rgb(75, 75, 75); font-size: 13px; font-family: georgia, verdana, Arial, helvetica, sans-seriff;">user</span><span style="color: rgb(75, 75, 75); font-size: 13px; font-family: georgia, verdana, Arial, helvetica, sans-seriff;">= (Item) getIntent().getSerializableExtra("user"); </span><span style="font-size:14px;color: rgb(75, 75, 75);">//這里就得到user對(duì)象了,注意:必須確保user</span><span style="font-family: georgia, verdana, Arial, helvetica, sans-seriff; line-height: 19.5px;"><span style="font-size:12px;color:#666666;">類實(shí)現(xiàn)Serializable或者Parcelable接口</span></span><span style="font-size:14px;color: rgb(75, 75, 75);"> }</span>

轉(zhuǎn)載于:https://www.cnblogs.com/jasonkent27/p/4098422.html

總結(jié)

以上是生活随笔為你收集整理的Intent 传递对象的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。