Android Intent Tutorial: Sending data from One Activity to another Activity
We can send data while calling one activity from another activity using intent. All we have to do is add the data to Intent object using putExtra() method. The data is passed in key value pair. The value can be of types like int, float, long, string, etc.
Sending Data
1
2
3
|
Intent intent = new Intent(context, DestinationActivityName.class);
intent.putExtra(Key, Value);
startActivity(intent);
|
Here I am sending just one value, in the same way you can attach more values by using putExtra() method.
Retrieving Data
If the data sent is of type string then it can be fetched in following way.
1
2
|
Intent intent = getIntent();
String str = intent.getStringExtra(Key);
|
To know more about Intent Go to this link
No comments:
Post a Comment