-6

I am passing custom ArrayList in putParcelableArrayListExtra, but when I receive it within onCreate method of other class, then some values of array are null

put...   get...

[a]  ->  [a]

[b]  ->  null

[c]  ->  [b]

[d]  ->  null

[e]  ->  [c]

I am sending data in intent.putParcelableArrayListExtra(key, value); and getting it as arrayList = getIntent().getParcelableArrayListExtra(key));

Kindly suggest how to solve this issue.

Sufian
  • 5,997
  • 14
  • 60
  • 111
Harneet Kaur
  • 4,347
  • 1
  • 12
  • 15
  • Without any parcelable code implementation it's anyones guess. What about sharing the necessary code...??? Try using http://www.parcelabler.com/ for generating the parcelable code and paste it inside your object. – Marko Feb 02 '16 at 08:57
  • Post your code of how you implement parcelable interface if it is an ArrayList of Object. – kopikaokao Feb 02 '16 at 08:58

3 Answers3

0

You can pass an ArrayList the same way, if the E type is Serializable.

You would call the putExtra (String name, Serializable value) of Intent to store, and getSerializableExtra (String name) for retrieval.

Example:

ArrayList<String> myList = new ArrayList<String>();
intent.putExtra("mylist", myList);

In the other Activity:

ArrayList<String> myList = (ArrayList<String>) getIntent().getSerializableExtra("mylist");
Suhas Bachewar
  • 1,234
  • 7
  • 20
  • 1
    Parcelable > Serializable in Android. Read this for more info [link](http://www.developerphil.com/parcelable-vs-serializable/) – kopikaokao Feb 02 '16 at 09:04
0

make all the classes that are used Parecelable. Then override writeToParcel and create public static final Parcelable.Creator<YourClass> to read from parcel and create an object from your object.

But the simplest will be to use Serializable interface. reading and writing will be automatically handled.

peeyush pathak
  • 3,645
  • 3
  • 16
  • 24
0
  1. Use a pojo/setter getter class with the implementation of Parcelable .

    public class MyData implements Parcelable
    
  2. Declare the values in your pojo which will be an arraylist item

    MyData data = new MyData("id", "text");
    
  3. Call the parcelable method from the intent with your another activity.

    Intent i = new Intent(this,MyActivity.class);
    i.putExtra("key", data);
    startActivity(i);
    
  4. Get the list with parcelable method of that class intent,

    MyData data = i.getExtras().getParcelable("key");
    List<MyData> mList = new ArrayList<>();
    mList.add(data);
    
Sufian
  • 5,997
  • 14
  • 60
  • 111
Nanda Gopal
  • 1,749
  • 13
  • 22