Android頁面之間進行數(shù)據(jù)回傳的方法分析
本文實例講述了Android頁面之間進行數(shù)據(jù)回傳的方法。分享給大家供大家參考,具體如下:
要求:頁面1跳轉到頁面2,頁面2再返回頁面1同時返回數(shù)據(jù)
頁面1添加如下代碼:
Intent intent = new Intent(); intent.setClass(頁面1.this, 頁面2.class); Bundle bundle = new Bundle(); intent.putExtras(bundle);//將Bundle添加到Intent,也可以在Bundle中添加相應數(shù)據(jù)傳遞給下個頁面,例如:bundle.putString("abc", "bbb"); startActivityForResult(intent, 0);// 跳轉并要求返回值,0代表請求值(可以隨便寫)
頁面2接收數(shù)據(jù)添加代碼如下:
Intent intent = this.getIntent(); Bundle bundle = intent.getExtras(); bundle.putString("aaa", "back");//添加要返回給頁面1的數(shù)據(jù) intent.putExtras(bundle); this.setResult(Activity.RESULT_OK, intent);//返回頁面1 this.finish();
頁面1接收返回數(shù)據(jù):(需要重寫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(); } }
更多關于Android相關內容感興趣的讀者可查看本站專題:《Android線程與消息機制用法總結》、《Android編程之activity操作技巧總結》、《Android調試技巧與常見問題解決方法匯總》、《Android開發(fā)入門與進階教程》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結》、《Android視圖View技巧總結》、《Android布局layout技巧總結》及《Android控件用法總結》
希望本文所述對大家Android程序設計有所幫助。
- Android基礎之使用Fragment控制切換多個頁面
- android使用webwiew載入頁面使用示例(Hybrid App開發(fā))
- Android使用Fragment打造萬能頁面切換框架
- Android編程實現(xiàn)ViewPager多頁面滑動切換及動畫效果的方法
- 詳解Android Activity之間切換傳遞數(shù)據(jù)的方法
- Android開發(fā)之利用Intent實現(xiàn)數(shù)據(jù)傳遞的方法
- Android中Service實時向Activity傳遞數(shù)據(jù)實例分析
- Android實現(xiàn)Activities之間進行數(shù)據(jù)傳遞的方法
- Android學習筆記--通過Application傳遞數(shù)據(jù)代碼示例
- 在Android系統(tǒng)中使用gzip進行數(shù)據(jù)傳遞實例代碼
- Android 不同Activity間數(shù)據(jù)的傳遞 Bundle對象的應用
- Android 使用Intent傳遞數(shù)據(jù)的實現(xiàn)思路與代碼
相關文章
Android使用RecyclerView實現(xiàn)投票系統(tǒng)
這篇文章主要為大家詳細介紹了Android使用RecyclerView實現(xiàn)投票系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-11-11Android TextView中文字通過SpannableString設置屬性用法示例
這篇文章主要介紹了Android TextView中文字通過SpannableString設置屬性用法,結合實例形式分析了TextView控件中SpannableString類相關屬性的使用技巧,需要的朋友可以參考下2016-08-08Android開發(fā)基于ScrollView實現(xiàn)的漸變導航欄效果示例
這篇文章主要介紹了Android開發(fā)基于ScrollView實現(xiàn)的漸變導航欄效果,涉及ScrollView事件響應及元素屬性動態(tài)操作相關實現(xiàn)技巧,需要的朋友可以參考下2017-12-12Android讀取本地json文件的方法(解決顯示亂碼問題)
這篇文章主要介紹了Android讀取本地json文件的方法,結合實例形式對比分析了解決顯示亂碼問題的方法,需要的朋友可以參考下2016-06-06Android組件DrawerLayout仿網(wǎng)易新聞v4.4側滑菜單
這篇文章主要為大家詳細介紹了Android組件DrawerLayout仿網(wǎng)易新聞v4.4側滑菜單,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-01-01