For this, Intent will start and the following methods will run: putExtra() method is used for send the data, data in key-value pair key is variable name and value can be Int, String, Float etc. getStringExtra() method is for getting the data(key) which is send by above method.
The Intent is not deprecated the problem is with your itemClickable. class because it is not recognized.
putExtra allows you to add primitive (or parcelable) key-value pairs. setData is limited to passing an Uri . setData is conventionally used for the case of requesting data from another source, such as in startActivityForResult. but an uri can be sent through putextra also.
Assuming that your List is a list of strings make data an ArrayList<String>
and use intent.putStringArrayListExtra("data", data)
Here is a skeleton of the code you need:
Declare List
private List<String> test;
Init List at appropriate place
test = new ArrayList<String>();
and add data as appropriate to test
.
Pass to intent as follows:
Intent intent = getIntent();
intent.putStringArrayListExtra("test", (ArrayList<String>) test);
Retrieve data as follows:
ArrayList<String> test = getIntent().getStringArrayListExtra("test");
Hope that helps.
If you use ArrayList instead of list then also your problem wil be solved. In your code only modify List into ArrayList.
private List<Item> data;
you can do it in two ways using
Serializable
Parcelable.
This examle will show you how to implement it with serializable
class Customer implements Serializable
{
// properties, getter setters & constructor
}
// This is your custom object
Customer customer = new Customer(name, address, zip);
Intent intent = new Intent();
intent.setClass(SourceActivity.this, TargetActivity.this);
intent.putExtra("customer", customer);
startActivity(intent);
// Now in your TargetActivity
Bundle extras = getIntent().getExtras();
if (extras != null)
{
Customer customer = (Customer)extras.getSerializable("customer");
// do something with the customer
}
Now have a look at this. This link will give you a brief overview of how to implement it with Parcelable.
Look at this.. This discussion will let you know which is much better way to implement it.
Thanks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With