欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android頁面之間進行數(shù)據(jù)回傳的方法分析

 更新時間:2016年06月02日 09:47:42   作者:aparche  
這篇文章主要介紹了Android頁面之間進行數(shù)據(jù)回傳的方法,結合實例形式分析了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程序設計有所幫助。

相關文章

最新評論