我如何从Android上的意图获得额外的数据?
我怎样才能将数据从一个活动(intent)发送到另一个?
我使用此代码发送数据:
Intent i=new Intent(context,SendMessage.class);
i.putExtra("id", user.getUserAccountId()+"");
i.putExtra("name", user.getUserFullName());
context.startActivity(i);
  首先,使用getIntent()方法获取开始活动的意图: 
Intent intent = getIntent();
  如果您的额外数据表示为字符串,则可以使用intent.getStringExtra(String name)方法。  在你的情况下: 
String id = intent.getStringExtra("id");
String name = intent.getStringExtra("name");
在接收活动中
Bundle extras = getIntent().getExtras(); 
String userName;
if (extras != null) {
    userName = extras.getString("name");
    // and get whatever type user account id is
}
//  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
上一篇: How do I get extra data from intent on Android?
下一篇: How to attach two or more files to SEND action on Android
