1

I am doing a "drawing-like" project which enables users to draw a path in ActivityB and then get a clipped photo when back to ActivityA, in which they can choose to save it for editing again next time.

The most important and the only information should be passed/saved is the (x,y) points user draws. I use two float arrays to store the value, and pass them as extra to ActivityA. (both of the float[] has a limited size, 500.)

intent.putExtra("EXTRA_X", xPoints);
intent.putExtra("EXTRA_Y", yPoints);

When saving into SQLite, I save two Strings converted from the float[] because SQLite doesn't support saving an array.

private String floatArrToStr(float[] arr) {
    StringBuilder s = new StringBuilder();
    for (int i = 0 ; i < length ; i++) {
        s.append(arr[i]);
        s.append(",");
    }
    return s.toString();
}

My question is, is this the best way to pass and save Points? Will using Parcelables be better (Android: Pass List<GeoPoint> to another Activity)?

Community
  • 1
  • 1
tddian
  • 43
  • 8

1 Answers1

0

You can pass a Serializable across activities.

Class PathPoint implements Serializable {
  public float x;
  public float y;
}

then ArrayList<PathPoint> is also Serializable, can be placed into a Bundle and sent across.

S.D.
  • 29,290
  • 3
  • 79
  • 130
  • As far as I know, `Serializable` is standard in JAVA but not suitable for Android due to efficiency – tddian Aug 25 '12 at 07:25
  • [Benefit of using Parcelable instead of serializing object](http://stackoverflow.com/a/5551155/1390612) – tddian Aug 25 '12 at 07:26
  • @tiddan quote from same link: "Parcelable is not meant to be passed to an activity." – S.D. Aug 25 '12 at 07:29
  • You can pass a Parcelable between activities. In [Android Developer](http://developer.android.com/reference/android/content/Intent.html) search for `putExtra (String name, Parcelable value)` – tddian Aug 25 '12 at 08:48
  • when to use serializable instead of Parceable? – Jeff Bootsholz May 14 '13 at 08:41
  • @RajuGujarati `Parcelable` is high performance, specially when two processes exchange data remotely. For most _within the same app_ scenarios, `serializable` will suffice. – S.D. May 14 '13 at 10:42