How can I send data from one activity (intent) to another?
I use 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);
I just posted an answer here that covers this topic in a bit more detail, including some alternatives.
It utilises Vapor API, a new jQuery inspired Android framework I wrote to simplify Android dev. Check out the example in that answer for how you can easily pass data between activites.
Also it demonstrates
VaporIntent
, which lets you chain method calls and utilise the overloaded.put(...)
method:You can easily pass data around your whole application using Vapor API, so hopefully it'll be helpful to you and others during app development.
First, get the intent which has started your activity using the
getIntent()
method:If your extra data is represented as strings, then you can use
intent.getStringExtra(String name)
method. In your case:You can also do like this
// put value in intent
// get value from intent
We can do it by simple means:
In FirstActivity:
In SecondActivity: