Android頁(yè)面之間進(jìn)行數(shù)據(jù)回傳的方法分析
本文實(shí)例講述了Android頁(yè)面之間進(jìn)行數(shù)據(jù)回傳的方法。分享給大家供大家參考,具體如下:
要求:頁(yè)面1跳轉(zhuǎn)到頁(yè)面2,頁(yè)面2再返回頁(yè)面1同時(shí)返回?cái)?shù)據(jù)
頁(yè)面1添加如下代碼:
Intent intent = new Intent();
intent.setClass(頁(yè)面1.this, 頁(yè)面2.class);
Bundle bundle = new Bundle();
intent.putExtras(bundle);//將Bundle添加到Intent,也可以在Bundle中添加相應(yīng)數(shù)據(jù)傳遞給下個(gè)頁(yè)面,例如:bundle.putString("abc", "bbb");
startActivityForResult(intent, 0);// 跳轉(zhuǎn)并要求返回值,0代表請(qǐng)求值(可以隨便寫(xiě))
頁(yè)面2接收數(shù)據(jù)添加代碼如下:
Intent intent = this.getIntent();
Bundle bundle = intent.getExtras();
bundle.putString("aaa", "back");//添加要返回給頁(yè)面1的數(shù)據(jù)
intent.putExtras(bundle);
this.setResult(Activity.RESULT_OK, intent);//返回頁(yè)面1
this.finish();
頁(yè)面1接收返回?cái)?shù)據(jù):(需要重寫(xiě)onActivityResult)
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 0 && resultCode == Activity.RESULT_OK) {
Bundle bundle = data.getExtras();
gameView.backString = bundle.getString("aaa");
Toast.makeText(this, backString, Toast.LENGTH_SHORT).show();
}
}
更多關(guān)于A(yíng)ndroid相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《Android線(xiàn)程與消息機(jī)制用法總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android調(diào)試技巧與常見(jiàn)問(wèn)題解決方法匯總》、《Android開(kāi)發(fā)入門(mén)與進(jìn)階教程》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
- Android基礎(chǔ)之使用Fragment控制切換多個(gè)頁(yè)面
- android使用webwiew載入頁(yè)面使用示例(Hybrid App開(kāi)發(fā))
- Android使用Fragment打造萬(wàn)能頁(yè)面切換框架
- Android編程實(shí)現(xiàn)ViewPager多頁(yè)面滑動(dòng)切換及動(dòng)畫(huà)效果的方法
- 詳解Android Activity之間切換傳遞數(shù)據(jù)的方法
- Android開(kāi)發(fā)之利用Intent實(shí)現(xiàn)數(shù)據(jù)傳遞的方法
- Android中Service實(shí)時(shí)向Activity傳遞數(shù)據(jù)實(shí)例分析
- Android實(shí)現(xiàn)Activities之間進(jìn)行數(shù)據(jù)傳遞的方法
- Android學(xué)習(xí)筆記--通過(guò)Application傳遞數(shù)據(jù)代碼示例
- 在A(yíng)ndroid系統(tǒng)中使用gzip進(jìn)行數(shù)據(jù)傳遞實(shí)例代碼
- Android 不同Activity間數(shù)據(jù)的傳遞 Bundle對(duì)象的應(yīng)用
- Android 使用Intent傳遞數(shù)據(jù)的實(shí)現(xiàn)思路與代碼
相關(guān)文章
Android 3.0引入的異步加載機(jī)制Loader
Loader裝載器從android3.0開(kāi)始引進(jìn)。它使得在activity或fragment中異步加載數(shù)據(jù)變得簡(jiǎn)單。下面我們就來(lái)詳細(xì)講解下2017-12-12
Android自定義樣式圓角dialog對(duì)話(huà)框
這篇文章主要為大家詳細(xì)介紹了Android自定義樣式圓角dialog對(duì)話(huà)框,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-11-11
Android仿今日頭條頂部導(dǎo)航欄效果的實(shí)例代碼
這篇文章主要介紹了Android之仿今日頭條頂部導(dǎo)航欄效果的實(shí)例代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,一起跟隨小編過(guò)來(lái)看看吧2018-05-05
android 軟鍵盤(pán)的POPUP布局的問(wèn)題解決
這篇文章主要介紹了android 軟鍵盤(pán)的POPUP布局的問(wèn)題解決,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-10-10

