how to serialize for android.location class?

Android's Location class already implements Parcelable. So you are better off with it rather than implementing your own Serialization.

Simply use the following to get bytes out from Location:

Parcel p = Parcel.obtain();
objLocation.writeToParcel(p, 0);
final byte[] b = p.marshall();      //now you've got bytes
p.recycle();

However, you should not save bytes (in persistent storage) from Parecelable object for later use because it is designed for high-performance IPC transport, and is not a general-purpose serialization mechanism.


You can not make a non-serializable class serializable just implementing the Serializable interface. A serializable class must inherit from a serializable class (if an inherited class) and have all its attributes serializable themselves.

All subtypes of a serializable class are themselves serializable. http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html

However, if you want to serialize a Parcelable class it is still possible, but surely it would not be a good practice.