android 通过网络发送对象时可打包
android Parcelable when sending object over network
我有一个对象要通过网络在文件中发送到 java servlet。我的对象看起来像这样:
public class MYPOJO implements Serializable {
int myint;
String mystring;
}
我读到不建议在 Android 中使用 Serializable,因为反射时间会增加延迟。但由于它不是另一个 activity 将使用我的对象,我认为我不应该使用 parcelable。我想我应该使用 Serializable 并将对象写入磁盘,然后通过网络将其发送到 java servlet 进行处理。写入磁盘是 speech.writing 到 java 流的数字。
问题是您建议如何使用 parcelable 执行此操作,甚至可能吗?是 paracelable 只推荐从 activity 到另一个 Activity ?
I think i should use Serializable and write the object to disk and then send it over the wire to the java servlet for processing.
我不知道您为什么需要将它写入磁盘。您可以将其写入由 ByteArrayOutputStream
支持的 ObjectOutputStream
并跳过磁盘 I/O.
就我个人而言,一百万年内我都不会将 Serializable
用于网络 I/O(使用 JSON 或 protobuf 或其他与平台无关的东西),但如果你要去使用它,至少要有效率。 :-)
How would you recommend doing this with parcelable is the question, is it even possible ?
没有。 Parcelable
用于进程间通信,而不是网络传输、持久性或 运行 设备外的其他场景。
is is paracelable only recommended from activity to another Activity ?
欢迎您将其用于其他IPC场景(例如,使用Parcelable
AIDL方法参数的远程服务)。
我有一个对象要通过网络在文件中发送到 java servlet。我的对象看起来像这样:
public class MYPOJO implements Serializable {
int myint;
String mystring;
}
我读到不建议在 Android 中使用 Serializable,因为反射时间会增加延迟。但由于它不是另一个 activity 将使用我的对象,我认为我不应该使用 parcelable。我想我应该使用 Serializable 并将对象写入磁盘,然后通过网络将其发送到 java servlet 进行处理。写入磁盘是 speech.writing 到 java 流的数字。
问题是您建议如何使用 parcelable 执行此操作,甚至可能吗?是 paracelable 只推荐从 activity 到另一个 Activity ?
I think i should use Serializable and write the object to disk and then send it over the wire to the java servlet for processing.
我不知道您为什么需要将它写入磁盘。您可以将其写入由 ByteArrayOutputStream
支持的 ObjectOutputStream
并跳过磁盘 I/O.
就我个人而言,一百万年内我都不会将 Serializable
用于网络 I/O(使用 JSON 或 protobuf 或其他与平台无关的东西),但如果你要去使用它,至少要有效率。 :-)
How would you recommend doing this with parcelable is the question, is it even possible ?
没有。 Parcelable
用于进程间通信,而不是网络传输、持久性或 运行 设备外的其他场景。
is is paracelable only recommended from activity to another Activity ?
欢迎您将其用于其他IPC场景(例如,使用Parcelable
AIDL方法参数的远程服务)。