3

I have a complex class that I used a @Parcelable (Im using the Parceler library https://github.com/johncarl81/parceler)

@Parcel
public class Event {
    public int id;
    public String title;
    public String description;
    public String resourceURL;
    public List<Url> urls;
    public Date modified;
    public Date start;
    public Date end;
    public ImageInfo thumbnail;
    public ItemList comics;
    public ItemList stories;
    public ItemList series;
    public CharacterList characters;
    public CreatorList creators;
    public Item next;
    public Item previous;
}

The class has many other objects, but theyre mostly strings.

I wrapped it in my main activity like:

Intent intent = new Intent(getApplicationContext(), EventDescriptionActivity.class);
Bundle bundle = new Bundle();
bundle.putParcelable("event", Parcels.wrap(eventList.get(position)));
intent.putExtras(bundle);
startActivity(intent);

I have an List of events (eventList) and im trying to send one object in the list to another activity.

I unwrap it in my other activity like:

Event event = Parcels.unwrap(this.getIntent().getExtras().get("event"));

Inside my onCreate()

But i get a red line under my parameter saying:

"unwrap (android.os.Parcelable) in Parcels cannot be applied to (java.lang.Object)"
John Ericksen
  • 10,995
  • 4
  • 45
  • 75
fred jones
  • 245
  • 1
  • 2
  • 10

2 Answers2

0

So I just pressed alt enter on the error line and it provided the proper type casting...i should alt enter more often

fred jones
  • 245
  • 1
  • 2
  • 10
0

This was originally a mistake in the documentation. The extra method using in conjunction with the Parcels.unwrap method is the getParcelableExtra method:

Event event = Parcels.unwrap(getIntent().getParcelableExtra("event"));
John Ericksen
  • 10,995
  • 4
  • 45
  • 75