zoukankan      html  css  js  c++  java
  • Android页面之间进行数据回传

    要求:页面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);//返回页面1
    this.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();
            }
    
        }
    复制代码
  • 相关阅读:
    java注解
    SpringBoot 整合 MybatisPlus 3.0
    第三章 列表简介
    第二章 变量及简单数据类型
    收藏通俗知识
    2017.8.13 列标,元组,字符串
    Python入门--4--分之和循环
    Python入门---易错已错易混淆----知识点
    Perl语言入门--4--函数
    perl学习之精髓中的精髓
  • 原文地址:https://www.cnblogs.com/wangluochong/p/4079222.html
Copyright © 2011-2022 走看看