Android开发:不同的Activity之间…

来源:互联网 发布:mac menu bar 设置 编辑:程序博客网 时间:2024/05/20 08:25

 Android的不同的Activity之间的数据传递,类似于桌面软件开发中不同窗体间的数据传递。

android通过bundle对象来传递数据

Activity1:

  文件名:Form1.java

       
       Intent intent = new Intent();
       intent.setClass(Form1.this, Form2.class);
       
       Bundle bundle = new Bundle();
       bundle.putDouble("param1", 176);
       bundle.putString("param2", 'hello');
       
       intent.putExtras(bundle);
       
       startActivity(intent);

Activity2:

  文件名:Form2.java

       
       Bundle bundle = this.getIntent().getExtras();

       
       String sex = bundle.getString("param1");
       double height = bundle.getDouble("param2");

 

原创粉丝点击