how to serialize for android.location class?

后端 未结 3 1846
青春惊慌失措
青春惊慌失措 2021-01-18 10:34

I\'m trying to serialize my location class (using android.location class)

but, it gives me an error!

11-21 21:25:37.337: W/System.err(3152): java.io.         


        
3条回答
  •  天命终不由人
    2021-01-18 11:10

    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.

提交回复
热议问题