0

Bit of a performance question. I have a fragment that fetched some data from the content provider and built an object which implements Parcelable.

MyObject object;

In the scenario where such objects is required in another fragment, what would be more convenient: pass the object as

args.putParcelable(ARG_KEY_OBJECT, object);

or pass the id of the object so that the new fragment can fetch it again from the content provider?

args.putString(ARG_KEY_OBJECT_ID, object.getId());

Furthermore: what if we're talking about a list of those objects?

ArrayList<MyObject> list = ....
args.putParcelableArrayList(ARG_KEY_OBJECT_LIST, list);
ticofab
  • 7,551
  • 13
  • 49
  • 90
  • If you already have the data, passing a parcelable will be faster. As the data does not need to be searched for and parsed into an object again. Though you should probably allow for both techniques, in the case where the fragment is created without the object being passed into it. – Knossos May 19 '15 at 10:51

1 Answers1

1

It turns out it is faster to pass the object as a parcelable. At the same time, this might not be the most convenient solution. For instance, passing the object ID and retrieving again in the new fragment is very handy if used in combination with an async loader, which can trigger callbacks if the stored object in the content provider changes.

ticofab
  • 7,551
  • 13
  • 49
  • 90