I asked a question the other day regarding sending an object to an activity using an intent as a parcel but I am unsure how to do it in my situation. I have a variable of type object Object x; which is set with something like this: x = edit.getText().toString(); and in this instance x becomes a String object but I also have it able to set x as both an Integer and an SQLDate type. Looking at examples of how to send an object as a parcel it seems to me you have to know what the datatype is before hand even for custom datatypes. Any help with this will be greatly appreciated as i’m completely stuck on this.
Flow is:
Object x; – is created.
x = String object||Integer object||sqldate object – x is assigned a value
i.putExtra("object", x); – x is sent through to the next activity after being parcelled.
The requirement on the data you pass inn is that it is serializable in some way, and yes, both
StringandIntegerare. Also, if you’re usingjava.sql.Date, this type inheritsutil.Datewhich in turn inheritsSerializable. The slight “problem” is thatIntent.putExtradoes not have an overload that takesObjectas parameter type. Thus, you would have to “know” which data type you want to put: