Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put set inside an Intent as an extra?

I have a Set where the class Prova implements Serializable. I must put this Set in a intent. This is the code:

Set<Prova> set=..... // Set is declared first and it's not null
Intent intent = new Intent(getApplicationContext(), Example.class);
intent.putExtra("set",set);

This code gives me: "cannot Resolve method". Anyone can help me?

like image 379
Doffy Avatar asked Feb 10 '23 09:02

Doffy


1 Answers

Try using HashSet instead of Set and then you can do something like this -

HashSet<Prova> set = new HashSet<>();
Intent intent = new Intent(getApplicationContext(), Example.class);
intent.putExtra("mySet", set);;

Set itself does not implement Serializable but HashSet does and Intent can hold an instance of any class that implements Serializable or Parcelable.

like image 70
Varundroid Avatar answered Feb 15 '23 11:02

Varundroid