要求:页面1跳转到页面2,页面2再返回页面1同时返回数据

页面1添加如下代码:

 Intent intent = new Intent();   intent.setClass(页面1.this, 页面2.class);   Bundle bundle = new Bundle();   intent.putExtras(bundle);//将Bundle添加到Intent,也可以在Bundle中添加相应数据传递给下个页面,例如:bundle.putString("abc", "bbb");   startActivityForResult(intent, 0);// 跳转并要求返回值,0代表请求值(可以随便写)

页面2接收数据添加代码如下:

Intent intent = this.getIntent();Bundle bundle = intent.getExtras();bundle.putString("aaa", "back");//添加要返回给页面1的数据intent.putExtras(bundle);this.setResult(Activity.RESULT_OK, intent);//返回页面1this.finish();

页面1接收返回数据:(需要重写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();        }    }

更多相关文章

  1. Android(安卓)给scrollView添加毛玻璃效果的标题栏
  2. 安卓利用百度api定位遇到 经纬度经纬度返回4.9E-324
  3. Android(安卓)8.0系统上使用WindowManager添加view的一个问题
  4. Android(安卓)Studio -添加你见过的最牛Log*神器*
  5. 2016.4.25
  6. android.support.v7包添加
  7. Android-Framework: Activity、Window、View三者之间的关系
  8. Android(安卓)之 ViewDragHelper详解(二)
  9. android中下拉框控件——Spinner

随机推荐

  1. [转]Android(安卓)开发中的日常积累
  2. Android(安卓)Layout XML属性
  3. Android(安卓)学习纲要
  4. android init language
  5. Your content must have a ListView whos
  6. android如何实现开机自动启动Service或ap
  7. android中ImageView的ScaleType属性
  8. 【Android布局】在程序中设置android:gra
  9. android wifi
  10. android编程中的琐碎知识点汇总(2)