• 28、activity之间传递数据&批量传递数据


     1 import android.app.Activity;
     2 import android.content.Intent;
     3 import android.os.Bundle;
     4 import android.view.View;
     5 import android.widget.EditText;
     6 
     7 /**
     8  * activity之间传递数据&批量传递数据
     9  * @author dr
    10  */
    11 public class Demo1Activity extends Activity {
    12     /** Called when the activity is first created. */
    13     @Override
    14     public void onCreate(Bundle savedInstanceState) {
    15         super.onCreate(savedInstanceState);
    16         setContentView(R.layout.main);
    17     }
    18     
    19     
    20     public void click(View view){
    21         EditText et = (EditText) this.findViewById(R.id.et_activity01);
    22         String content = et.getText().toString().trim();
    23         
    24         Intent intent = new Intent(this,Demo2Activity.class);
    25         // intent.putExtra("cn.itcast.passdata.name", content);
    26         //基本数据类型 和基本数据类型的数组 我们都可以通过intent传递 
    27         
    28         // 批量传递数据
    29         Bundle bundle = new Bundle();
    30         bundle.putString("cn.itcast.passdata.name", content);
    31         
    32         intent.putExtras(bundle);
    33         
    34         startActivity(intent);
    35     }
    36 }
     1 import android.app.Activity;
     2 import android.content.Intent;
     3 import android.os.Bundle;
     4 import android.widget.TextView;
     5 
     6 public class Demo2Activity extends Activity {
     7     @Override
     8     public void onCreate(Bundle savedInstanceState) {
     9         super.onCreate(savedInstanceState);
    10         setContentView(R.layout.main2);
    11         
    12         //获取到激活他的意图
    13         Intent intent = getIntent();
    14        // String name = intent.getStringExtra("cn.itcast.passdata.name");
    15          Bundle bundle =  intent.getExtras();
    16          String name =  bundle.getString("cn.itcast.passdata.name");
    17         
    18          TextView tv  =(TextView) this.findViewById(R.id.tv_activity02);
    19          tv.setText("你好 :"+name);
    20     }
    21 }
  • 相关阅读:
    TI CC2541的整体目标
    TI CC2541的GPIO引脚设置.
    E2PROM与Flash的引脚图
    TI BLE CC2541的通讯协议.
    TI BLE CC2541的I2C主模式
    Charles如何抓取电脑上的请求的https数据包
    Charles如何抓取手机上的请求的https数据包
    谷歌浏览器chrome调试H5页面 如果添加cookie?
    Unity 好坑的Save Scene
    Unity 官网教程 -- Multiplayer Networking
  • 原文地址:https://www.cnblogs.com/androidsj/p/3965997.html
Copyright © 2020-2023  润新知