-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
  • 6,405
  • 16
  • 66
  • 120
Harneet Kaur
  • 4,487
  • 1
  • 16
  • 16
  • 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

2 Answers2

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,663
  • 3
  • 19
  • 25
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
  • 6,405
  • 16
  • 66
  • 120
Nanda Gopal
  • 2,519
  • 1
  • 17
  • 25