Reputation: 575
How I can use the intent to send the data to the second class?
I am doing this actually
Intent connectGetData = new Intent(Main.this, GetData.class);
startActivityForResult(connectGetData, REQUEST_GET_DATA);
From Main.java
activity I am calling the Getdata.java
activity and I when come back I again get data using.
public void onActivityResult(int mRequestCode, int mResultCode, Intent mDataIntent)
Please tell me how I can send data to other activity
Upvotes: 1
Views: 4455
Reputation: 2224
At sending activity...
Intent intent = new Intent(current.this, next.class);
intent.putextra("keyName","value");
startActivity(intent);
At receiving activity...
String data = getIntent().getExtras().getString("keyName");
Thus you can have data at receiving activity from sending activity...
Upvotes: 6
Reputation: 63293
You pass data along with the Intent using two mechanisms, depending on the needs of your application.
Intent.setData()
: This is a URI that you can use to indicate the location of a resource the new Activity may need to useIntent.putExtra()
: You can attach as many extras to an Intent as you like to represent the data you need to pass (both forwards to the new Activity and backwards with the result). Extras can be any primitive or easily serializable object.HTH
Upvotes: 6