Android開發(fā)Intent跳轉(zhuǎn)傳遞list集合實(shí)現(xiàn)示例
引言
- Android 兩個(gè)activity之間普通傳值 如:單個(gè)String ,int ... 就不多說了
- 參考文章 http://www.dhdzp.com/article/257178.htm
傳遞list集合
注意:list傳值的實(shí)體類用序列化
- 先創(chuàng)建個(gè)實(shí)體類(等下測試用)
import java.io.Serializable;
//別忘了序列化 Serializable
public class DemoBean implements Serializable {
String xm;
int age;
public String getXm() {
return xm;
}
public void setXm(String xm) {
this.xm = xm;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
- 第一個(gè)activity
//寫個(gè)測試方法
public void ToJump(){
List<DemoBean> list=new ArrayList<>();
//給list 添加 5 條數(shù)據(jù)
for (int i=0;i<5;i++){
DemoBean demoBean=new DemoBean();
demoBean.setXm("花花"+i);
demoBean.setAge(i);
list.add(demoBean);
}
Intent intent=new Intent(this,MainActivity.class);
intent.putExtra("list", (Serializable) list);
startActivity(intent);
}
- 第二個(gè)activity頁面接收
Intent intent=getIntent();
List<DemoBean> list= (List<DemoBean>) intent.getSerializableExtra("list");
Log.e("TAG","---"+list.size());// list.size()==5
傳遞ArrayList集合
傳遞ArrayList集合和list一樣
注意:實(shí)體類用序列化
- 第一個(gè)activity
public void ToJump(){
ArrayList<DemoBean> arrayList=new ArrayList();
for (int i=0;i<5;i++){
DemoBean demoBean=new DemoBean();
demoBean.setXm("花花"+i);
demoBean.setAge(i);
arrayList.add(demoBean);
}
Intent intent=new Intent(this,MainActivity.class);
intent.putExtra("arrayList",arrayList);
startActivity(intent);
}
- 第二個(gè)activity頁面接收
Intent intent=getIntent();
ArrayList<DemoBean> arrayList= (ArrayList<DemoBean>) intent.getSerializableExtra("arrayList");
Log.e("TAG","--------"+arrayList.size());// 有5條數(shù)據(jù) list.size()==5
傳遞實(shí)體類
- 第一個(gè)activity
public void ToJump(){
DemoBean demoBean=new DemoBean();
Intent intent=new Intent(this,MainActivity.class);
intent.putExtra("demoBean",demoBean);
startActivity(intent);
}
- 第二個(gè)activity頁面接收
Intent intent=getIntent();
DemoBean demoBean= (DemoBean) intent.getSerializableExtra("demoBean");
//接收到一整個(gè)實(shí)體類
傳遞String
- 第一個(gè)activity
Intent intent = new Intent(this,MainActivity2.class);
//設(shè)置傳遞鍵值對
intent.putExtra("name","花花");
//激活意圖
startActivity(intent);
- 第二個(gè)activity頁面接收
Intent intent = getIntent();
//獲取傳遞的值
String name= intent.getStringExtra("name");
//name的值是:花花
以上就是Android開發(fā)Intent跳轉(zhuǎn)傳遞list集合實(shí)現(xiàn)示例的詳細(xì)內(nèi)容,更多關(guān)于Android Intent跳轉(zhuǎn)傳遞list集合的資料請關(guān)注腳本之家其它相關(guān)文章!
- Android顯式Intent與隱式Intent的使用詳解
- Android Intent傳遞大量數(shù)據(jù)出現(xiàn)問題解決
- Android13?加強(qiáng)Intent?filters?的安全性
- android使用intent傳遞參數(shù)實(shí)現(xiàn)乘法計(jì)算
- Android使用Intent的Action和Data屬性實(shí)現(xiàn)點(diǎn)擊按鈕跳轉(zhuǎn)到撥打電話和發(fā)送短信界面
- Android Intent傳遞數(shù)據(jù)大小限制詳解
- Android開發(fā)中Intent.Action各種常見的作用匯總
- Android使用Intent隱式實(shí)現(xiàn)頁面跳轉(zhuǎn)
- Android Intent實(shí)現(xiàn)頁面跳轉(zhuǎn)的兩種方法
- Android Intent基礎(chǔ)用法及作用詳解
相關(guān)文章
如何正確理解和使用Activity的4種啟動(dòng)模式
本文主要介紹了如何正確理解和使用Activity的4種啟動(dòng)模式。具有很好的參考價(jià)值。下面跟著小編一起來看下吧2017-03-03
android AlertDialog的簡單使用實(shí)例
本篇文章主要介紹了android AlertDialog的簡單使用實(shí)例,具有一定的參考價(jià)值,有興趣的可以了解一下。2017-01-01
Android使用Scrolling機(jī)制實(shí)現(xiàn)Tab吸頂效果
app 首頁中經(jīng)常要實(shí)現(xiàn)首頁頭卡共享,tab 吸頂,內(nèi)容區(qū)通過 ViewPager 切換的需求,以前往往是利用事件處理來完成,但是這些也有一定的弊端和滑動(dòng)方面不如意的地方,本文我們利用NestedScrolling機(jī)制來實(shí)現(xiàn),感興趣的朋友可以參考下2024-01-01
Android?手寫RecyclerView實(shí)現(xiàn)列表加載
這篇文章主要介紹了Android?手寫RecyclerView實(shí)現(xiàn)列表加載,涉及到列表的需求,肯定第一時(shí)間想到RecyclerView,即便是自定義View,那么RecyclerView也會(huì)是首選,為什么會(huì)選擇RecyclerView而不是ListView,主要就是RecyclerView的內(nèi)存復(fù)用機(jī)制,這也是RecyclerView的核心?2022-08-08
詳解Android Activity之間切換傳遞數(shù)據(jù)的方法
這篇文章主要介紹了詳解Android Activity之間切換傳遞數(shù)據(jù)的方法 的相關(guān)資料,需要的朋友可以參考下2016-04-04
iOS中給UITableView的側(cè)滑刪除增加多個(gè)按鈕的實(shí)現(xiàn)方法
在項(xiàng)目中遇到這樣一個(gè)需求,cell的側(cè)滑刪除默認(rèn)只有一個(gè)刪除按鈕, 給側(cè)滑添加多個(gè)按鈕, '刪除', '置頂', '更多'.怎么實(shí)現(xiàn)呢?下面小編給大家分享iOS中給UITableView的側(cè)滑刪除增加多個(gè)按鈕的實(shí)現(xiàn)方法,一起看看吧2017-02-02
Android Flutter實(shí)現(xiàn)彈幕效果
這篇文章主要為大家詳細(xì)介紹如何利用Android FLutter實(shí)現(xiàn)彈幕效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-06-06

