I am creating a class that Implements the Parcelable,.
public class PosicaoResumoMobile implements Parcelable {
private Float _Latitude;
private Float _Longitude;
private org.joda.time.DateTime _DataHora;
...
But this class has an attribute of type org.joda.time.DateTime. How can I write this attribute in the following method implementing the Parcelable since it is not possible out.writeDateTime (_DataHora).
@Override
public void writeToParcel(Parcel out, int flags)
{
//TODO: How to write org.joda.time.DateTime
out.writeFloat(_Latitude);
out.writeFloat(_Longitude);
}
and read
private PosicaoResumoMobile(Parcel in){
//TODO: How to read org.joda.time.DateTime
Float latitude = in.readFloat();
Float longitude = in.readFloat();
}
You should be able to get the milliseconds using getMillis()
// to write to parcel
out.writeFloat(_Latitude);
out.writeLong(jodaDTInstance.getMillis())
// to read from parcel
Float longitude = in.readFloat();
jodaDTInstance = new DateTime(in.readLong());
Based on @artworkad comment, if you need to include Timezone information, you will have to use toString() and DateTime.parse():
To write to parcel:
dest.writeString(mDateTime.toString());
To read from parcel:
mDateTime = DateTime.parse(in.readString());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With