I'm trying to figure out what is the most efficient way to pass an object from one activity to another in android. I read I can extend an object as Parcelable or Serializable, and it seems like Parcelable is the clear winner in terms of performance.
Now I just thought of a different way. Instead of extending any class, I'll put all my data variables into a bundle, pass those data, and reconstruct the object. For example:
public class myObject {
// Data Variables
private String str1;
private String str2;
private boolean bool1;
// Constructor
public myObject(String str1, String str2, boolean bool1){
this.str1 = str1;
this.str2 = str2;
this.bool1 = bool1;
}
}
Now I'll just pass the variables:
Intent i = new Intent();
i.setClass(ActOne.this, ActTwo.class);
Bundle bundle = new Bundle();
bundle.putString("KEY_STR1", str1);
bundle.putString("KEY_STR2", str2);
bundle.putBoolean("KEY_BOOL1", bool1);
startActivity(i);
In the ActTwo class, I'll get the data from the intent and reconstruct my object:
myObject newObjHolder = new myObject(str1, str2, bool1);
How does this way compare to passing a Parcelable? Faster? Slower? Barely any difference?