Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

How do I get extra data from intent on Android?

How might I send information from one activity (intent) to another?

I utilize this code to send data:

Intent i=new Intent(context,SendMessage.class);
i.putExtra("id", user.getUserAccountId()+"");
i.putExtra("name", user.getUserFullName());
context.startActivity(i);
by

2 Answers

rahul07
First, get the intent which has started your activity using the getIntent() method:

Intent intent = getIntent();

If your extra data is represented as strings, then you can use intent.getStringExtra(String name) method. In your case:

String id = intent.getStringExtra("id");
String name = intent.getStringExtra("name");
RoliMishra
In the receiving activity

Bundle extras = getIntent().getExtras(); 
String userName;

if (extras != null) {
userName = extras.getString("name");
// and get whatever type user account id is
}

Login / Signup to Answer the Question.