我如何从Android的意图中获得额外的数据?如何将数据从一个活动(意图)发送到另一个活动(意图)?我使用此代码发送数据:Intent i=new Intent(context,SendMessage.class);i.putExtra("id", user.getUserAccountId()+"");
i.putExtra("name", user.getUserFullName());context.startActivity(i);
3 回答
Smart猫小萌
TA贡献1911条经验 获得超7个赞
getIntent()
Intent intent = getIntent();
intent.getStringExtra(String name)
String id = intent.getStringExtra("id");String name = intent.getStringExtra("name");
翻阅古今
TA贡献1780条经验 获得超5个赞
Bundle extras = getIntent().getExtras(); String userName;if (extras != null) { userName = extras.getString("name"); // and get whatever type user account id is}
拉丁的传说
TA贡献1789条经验 获得超8个赞
// How to send value using intent from one class to another class// class A(which will send data) Intent theIntent = new Intent(this, B.class); theIntent.putExtra("name", john); startActivity(theIntent);// How to get these values in another class// Class B Intent i= getIntent(); i.getStringExtra("name");// if you log here i than you will get the value of i i.e. john
- 3 回答
- 0 关注
- 564 浏览
添加回答
举报
0/150
提交
取消