如何为我的 class 实现 Parcelable 对象?
How to implement Parcelable object for my class?
我有 class 用于创建连接到服务器的客户端。它有以下成员:
public class MyClientThread implements Runnable, Parcelable {
private TextView ClientServerMsg;
private Integer PortNumber = 4545;
private String IPAddress = "127.0.0.1";
private Activity activity;
private Socket clientSocket;
}
当用户旋转屏幕时,所有客户端对象数据都是lost/reset,客户端必须重新连接到服务器。
在执行 writeToParcel
方法时,我 运行 遇到了问题,即如何打包 Socket
和 Thread
class 对象等等?
How to parcel Socket and Thread class object and such?
你不能。
When the user rotates the screen, all the client object data is lost/reset and the client has to be reconnected with server.
使用保留的片段,或 onRetainNonConfigurationInstance()
,或基于 lifecycle architecture components 的东西(例如,可能 LiveData
),以跨配置更改保留它。
我有 class 用于创建连接到服务器的客户端。它有以下成员:
public class MyClientThread implements Runnable, Parcelable {
private TextView ClientServerMsg;
private Integer PortNumber = 4545;
private String IPAddress = "127.0.0.1";
private Activity activity;
private Socket clientSocket;
}
当用户旋转屏幕时,所有客户端对象数据都是lost/reset,客户端必须重新连接到服务器。
在执行 writeToParcel
方法时,我 运行 遇到了问题,即如何打包 Socket
和 Thread
class 对象等等?
How to parcel Socket and Thread class object and such?
你不能。
When the user rotates the screen, all the client object data is lost/reset and the client has to be reconnected with server.
使用保留的片段,或 onRetainNonConfigurationInstance()
,或基于 lifecycle architecture components 的东西(例如,可能 LiveData
),以跨配置更改保留它。