Data transfer in Intent

1.An intent can contain additional data for target component.
2.Bundle class is used for achieving data transfer between android activities
3.For adding data to Bundle   use putExtra()
4.It will be always in key-value pair format
5.key will be always type of String
6.value can be primitive data type,Bundle,Parceable and Serializable.

How to pass data in Intent?

Intent intent = new Intent(MainActivity.this,SubActivity.class);
intent.putExtra(“KEY”,”Hello”);
startActivity(intent);

How to Get data from Intent?

Bundle bundle = getIntent().getExtras();
String got = bundle.getString(“KEY”);
* write inside onCreate();

Find Full code in this link

https://github.com/kavidriod/DataTranferViaIntent

Advertisements