-1

In android I have an ArrayListas follows:

ArrayList<SinglePoint> pointlist = new ArrayList<SinglePoint>();

which I will with content. When I am finished with the current activity, I need to transmit this object pointlist to a new activity. I tried the following (as I have found in several SO answers):

intent.putParcelableArrayListExtra("pointlist", pointlist);

and in the new activity I have the line

ArrayList<SinglePoint> pointlist = (ArrayList<SinglePoint>)getIntent().getSerializableExtra("pointlist");

but for the second line I get the error

Error:(40, 56) error: incompatible types: ArrayList<SinglePoint> cannot be converted to ArrayList<? extends Parcelable>

How to fix that?

I also tried the suggestion here which also does not work.

And with the following code as suggested here

intent.putExtra("pointlist", pointlist);

and

ArrayList<SinglePoint> pointlist = (ArrayList<SinglePoint>)getIntent().getSerializableExtra("pointlist");

I get the error

java.lang.RuntimeException: Parcel: unable to marshal value com.impyiablue.checkpoint.tools.SinglePoint@2f4a7cec
Alex
  • 41,580
  • 88
  • 260
  • 469
  • 1
    Does SinglePoint implement Parcelable? – Raghunandan Nov 11 '17 at 16:03
  • No. What is Parcelable? – Alex Nov 11 '17 at 16:03
  • You need SinglePoint implement Parcelable to pass list to other activity. https://developer.android.com/reference/android/os/Parcelable.html – Raghunandan Nov 11 '17 at 16:04
  • And then I must define some extra functions? Why is this so complicated...? – Alex Nov 11 '17 at 16:06
  • As @Raghunandan says, you need to implement `Parcalable` in your SinglePoint if you want to use `putParcelableArrayListExtra`. Or implement `Serializable` if you want to use `PutSerializable`. – ישו אוהב אותך Nov 11 '17 at 16:07
  • also if your list in huge i would recommend storing it persistently and then retrieve it in another activity. There is a limit as to how much data you can transfer. Not sure of the exact limit value – Raghunandan Nov 11 '17 at 16:08
  • `.getSerializableExtra("pointlist")` <-- `getParcelableArrayListExtra("pointlist")`, surely? (In addition to the fact that `SinglePoint` will need to implement `Parcelable`...) – PPartisan Nov 11 '17 at 16:09
  • How do I flatten my object with two objects in it? A String and a Long? – Alex Nov 11 '17 at 16:10
  • 1
    You need extra code if you want to implement Parcelable. You only need to add implement Serializable to your SinglePoint if you want to use Serializable. Like this: `SinglePoint implements Serializable{ }` – ישו אוהב אותך Nov 11 '17 at 16:10
  • With serialisable it did work! Thanks – Alex Nov 11 '17 at 16:12
  • 1
    @Alex use parcelable instead of searlization https://www.3pillarglobal.com/insights/parcelable-vs-java-serialization-in-android-app-development – Raghunandan Nov 11 '17 at 16:16
  • https://stackoverflow.com/a/46752761/3395198 Use Parcelable – IntelliJ Amiya Nov 11 '17 at 16:21
  • Congrats! Btw, most people tell that Parcelable is more faster than Serializable. But please look at this test project: https://bitbucket.org/afrishman/androidserializationtest. For persisting the data, use Serializable. Never use Parcelable for it! – ישו אוהב אותך Nov 11 '17 at 16:23

1 Answers1

0

You only need to implement the Parcelable interface for SinglePoint

This could help AndroidParcelable

floydheld
  • 314
  • 2
  • 11