Pass 2D array to another Activity

You can use putSerializable. Arrays are serializable. To store: bundle.putSerializable(“list”, selected_list); // Here bundle is Bundle object. To access: String[][] passedString_list = (String[][]) bundle.getSerializable(“list”); Example Intent mIntent = new Intent(this, Example.class); Bundle mBundle = new Bundle(); mBundle.putSerializable(“list”, selected_list); mIntent.putExtras(mBundle);

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

Is using Serializable in Android bad?

For in-memory use, Parcelable is far, far better than Serializable. I strongly recommend not using Serializable. You can’t use Parcelable for data that will be stored on disk (because it doesn’t have good guarantees about data consistency when things change), however Serializable is slow enough that I would strongly urge not using it there either. … Read more

how to properly implement Parcelable with an ArrayList?

You almost got it ! You just need to do : public void writeToParcel(Parcel out, int flags) { out.writeString(_mac); out.writeString(_pan); out.writeInt(_band); out.writeSerializable(_lqis); out.writeTypedList(_devices); } private ZigBeeNetwork(Parcel in) { _mac = in.readString(); _pan = in.readString(); _band = in.readInt(); _lqis = (ArrayList<Integer>) in.readSerializable(); in.readTypedList(_devices, ZigBeeDev.CREATOR); } That’s all! For your list of Integer, you can also do … 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

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.