Androidew1267
Androidew1267

Reputation: 623

How to pass custom objects between activities?

I need to pass list of objects which contain fields such as Face(from Microsoft' Face client library) and Bitmap. I have read about Parcelable and Serializable but if I understood correctly, it doesn't allow for passing objects such as Face. Is this any possibility to do this?

Upvotes: 0

Views: 44

Answers (1)

Vinicius Almada
Vinicius Almada

Reputation: 394

A common way to pass data between activities is through Intent or Bundles, those objects can store objects that implemented Parcelable interface. As you are using, it seems to me, third-party objects, you must ensure that these objects implements the Parcelable or Serializable interfaces, otherwise, you can create a Face subclass and implements the required interfaces to pass through Intents, like:

MyFace face = ...;
Intent intent = new Intent();
intent.putExtra(KEY_FACE, face);

And later, on the other Activity, you can get the extras from getIntent() Activity function.

Upvotes: 1

Related Questions