java activity传值

葫芦的运维日志

下一篇 搜索 上一篇

浏览量 4089

2014/04/21 02:05


1、通过bundle传值:
mainactivity:
Intent intent = new Intent();
          intent .setClass(this, Command. class);
          Bundle bundle = new Bundle();
          bundle.putString( "title", title);
          bundle.putInt( "statement", statement); // 要传递的数据
          intent. putExtras(bundle);
          startActivity(intent);

command activity:
           int st= this.getIntent().getExtras().getInt( "statement");
          String tt=this.getIntent().getExtras().getString( "title");

2、直接传值
主:
Intent intent=new Intent(MainActivity.this,NextActivity.class);
intent.putExtra("name","jack");
intent.putExtra("age",23);
intent.putExtra("address","北京");
Bundle bundle=new Bundle();
bundle.putString("code","1001");
intent.putExtra("bundle",bundle);
startActivity(intent);
副:
Intent intent=getIntent();
String name=intent.getStringExtra("name");
int age=intent.getIntExtra("age",0);
String address=intent.getStringExtra("address");
Bundle bundle=intent.getBundleExtra("bundle");
String code=bundle.getString("code");

 

葫芦的运维日志

打赏

上一篇 搜索 下一篇
© 冰糖葫芦甜(bthlt.com) 2021 王梓打赏联系方式 陕ICP备17005322号-1