Venkatesh Achanta
Venkatesh Achanta

Reputation: 654

Android : Bundle Vs Intent

I'm able to pass String (which is an object) to another activity through intent. But whenever I tried to pass some other class object (eg: "LatLng" class object) through intent to another activity, seeing runtime errors. What is the difference between sting object and LatLng class object in this context?

Note: I'm able to pass LatLng class object through bundle without any issues, but I just wanted to know the reason.

Upvotes: 0

Views: 2349

Answers (1)

Triode
Triode

Reputation: 11357

You can pass all the primitive type values in Intent as it is, like String, int, boolean etc. In case of String type by default it implements Serializable.

public final class
String
extends Object
implements Serializable CharSequence Comparable<T>

Reference

But if you have a complex object that you want to pass inside a Bundle either you have to make it Serializable or Parcelable. Since Serializable is java native implementation and it was not designed for Portable devices like Mobile. So if you really consider about performance you have to use Parcelable instead. Google itself promote the use of Parcelable.

But in your case LatLng implements Parcelable. So you can use

putParcelable(String key, Parcelable value)

And to access this use below method.

public T getParcelable (String key);

Upvotes: 2

Related Questions