简体   繁体   中英

android intents - passing data

How to pass and get "myobject1" between two activities?

First activity:

private ArrayList<Custom> myobject1 = new ArrayList<Custom>();
...
i.putExtra("myobject1", myobject1);

Second activity:

results =(ArrayList<Custom>) getIntent().getSerializableExtra("myobject1");

Here is my Custom.class :

public class Custom implements Comparable<Custom>{


    private String big;
    private String small;

    public Custom(String n,String d)
    {
        big = n;
        small = d;

    }
    public String getFirst()
    {
        return big;
    }
    public String getSecond()
    {
        return small;
    }

    @Override
    public int compareTo(Custom o) {
        if(this.big != null)
            return this.big.toLowerCase().compareTo(o.getFirst().toLowerCase()); 
        else 
            throw new IllegalArgumentException();
    }
}

At this moment I'm getting error: E/AndroidRuntime(8032): java.lang.RuntimeException: Parcel: unable to marshal value

In order to pass a value from an Activity to another the Class of the object you try to pass should implement the Parcelable interface. You can find more info here http://developer.android.com/reference/android/os/Parcelable.html . In case you need anything more specific, please shoot it!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM