8

I am trying to pass an ArrayList of Objects between multiple activities in my application. Is it possible to do this using an Intent using the setData() method?

0

6 Answers 6

12

If you want to send an ArrayList of objects then your class must implement the Parcelable or Serializable interface .

See these good tutorials for sending custom object between Activities

http://androidideasblog.blogspot.in/2010/02/passing-list-of-objects-between.html

http://www.anddev.org/novice-tutorials-f8/simple-tutorial-passing-arraylist-across-activities-t9996.html

Sign up to request clarification or add additional context in comments.

2 Comments

The first link had clear enough instructions and a working example. Thanks.
Guys , I have problem I'm getting TransactionTooLargeException when I pass large Arraylist Using Parcelable or Serializable . Need help on that.
6

Use below code for pass arraylist in intent.

Intent mIntent = new Intent(FirstActivity.this, SecondActivity.class);
mIntent.putParcelableArrayListExtra("Data", mArraylist);
startActivity(mIntent);

Use below code For get arraylist from Intent.

Bundle bdl = getIntent().getExtras();
mArraylist1 = bdl.getParcelableArrayList("Data");

Comments

3

First you need to extend parcelable class in your Object class. Then you can pass it through intent via intent.putParcelableArrayListExtra("PASSING_DATA", data);

here data is arraylist of custom objects.

see Parcelable and Parcelable Tutorial for better undertanding

Comments

0

If the objects implement Parcelable you can use the putParcelableArrayList method like this:

Bundle data = new Bundle();
data.putParcelableArrayList("myArrayList", myList);
Intent i = new Intent();
i.putExtra("data", data);

Hope that helps.

1 Comment

Yes, it works if the objects in the ArrayList implement Parcelable.
0

yes, it is possible... You need to implement Serializable class by your object class.

Comments

0

You can make the arraylist static where you are defining it, and only pass the position to the next activity

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.