Pass ArrayList

The problem is in writing out to the parcel and reading in from the parcel … @Override public void writeToParcel(Parcel dest, int flags) { dest.writeString(name); dest.writeInt(numOfSeason); dest.writeInt(numOfEpisode); } private void readFromParcel(Parcel in) { name = in.readString(); numOfSeason = in.readInt(); numOfEpisode = in.readInt(); } What you write out has to match what you read in… @Override … Read more

Read & writing arrays of Parcelable objects

You need to write the array using the Parcel.writeTypedArray() method and read it back with the Parcel.createTypedArray() method, like so: MyClass[] mObjList; public void writeToParcel(Parcel out) { out.writeTypedArray(mObjList, 0); } private void readFromParcel(Parcel in) { mObjList = in.createTypedArray(MyClass.CREATOR); } The reason why you shouldn’t use the readParcelableArray()/writeParcelableArray() methods is that readParcelableArray() really creates a Parcelable[] … Read more

How to save custom ArrayList on Android screen rotate?

You do not need to create a new class to pass an ArrayList of your custom objects. You should simply implement the Parcelable class for your object and use Bundle#putParcelableArrayList() in onSaveInstanceState() and onRestoreInstanceState(). This method will store an ArrayList of Parcelables by itself. Because the subject of Parcelables (and Serializables and Bundles) sometimes makes … Read more

Android: How to pass Parcelable object to intent and use getParcelable method of bundle?

Intent provides bunch of overloading putExtra() methods. Suppose you have a class Foo implements Parcelable properly, to put it into Intent in an Activity: Intent intent = new Intent(getBaseContext(), NextActivity.class); Foo foo = new Foo(); intent.putExtra(“foo “, foo); startActivity(intent); To get it from intent in another activity: Foo foo = getIntent().getExtras().getParcelable(“foo”); Hope this helps.

Help with passing ArrayList and parcelable Activity

I can see a number of problems here: Why use addressParcelable? Why not make address implement Parcelable, and then use: intent.putParcelableArrayListExtra( “addresses”, addyExtras ); Your parcelable object must include a static CREATOR. See the documentation for details. You are not actually adding any extras to the intent before you call startActivity(). See point 1 for … Read more

How to marshall and unmarshall a Parcelable to a byte array with help of Parcel?

First create a helper class ParcelableUtil.java: public class ParcelableUtil { public static byte[] marshall(Parcelable parceable) { Parcel parcel = Parcel.obtain(); parceable.writeToParcel(parcel, 0); byte[] bytes = parcel.marshall(); parcel.recycle(); return bytes; } public static Parcel unmarshall(byte[] bytes) { Parcel parcel = Parcel.obtain(); parcel.unmarshall(bytes, 0, bytes.length); parcel.setDataPosition(0); // This is extremely important! return parcel; } public static <T> … Read more

How to pass ArrayList of Objects from one to another activity using Intent in android?

Between Activity: Worked for me ArrayList<Object> object = new ArrayList<Object>(); Intent intent = new Intent(Current.class, Transfer.class); Bundle args = new Bundle(); args.putSerializable(“ARRAYLIST”,(Serializable)object); intent.putExtra(“BUNDLE”,args); startActivity(intent); In the Transfer.class Intent intent = getIntent(); Bundle args = intent.getBundleExtra(“BUNDLE”); ArrayList<Object> object = (ArrayList<Object>) args.getSerializable(“ARRAYLIST”); Hope this help’s someone. Using Parcelable to pass data between Activity This usually works when … Read more

Passing arraylist of objects between activities

You try the below intent.putParcelableArrayListExtra(“key”, ArrayList<T extends Parcelable> list); startActivity(intent); Retrieve it getIntent().getParcelableArrayListExtra(“key”); Pass arraylist of user defined objects to Intent android. Check the answer by Sajmon According to the comments made by Sajmon, Song class has to implement Parcelable