2

我在 Parcelable 对象中有一个可序列化的对象(ArrayList)。我正在尝试读取可序列化的对象,但在阅读后我无法弄清楚如何准确地重建它:

public class WifiAP implements Parcelable {

public String _mac;
public String _mac2;
public String _ssid;
public boolean _dualband;
public int _band;  // kilohertz
public int _band2;
ArrayList<Integer> _rssis;

public Packet _beacon;

public void writeToParcel(Parcel out, int flags) {
    out.writeString(_mac);
    out.writeString(_mac2);
    out.writeString(_ssid);

    if(_dualband)
        out.writeInt(1);
    else
        out.writeInt(0);

    out.writeInt(_band);
    out.writeInt(_band2);
    out.writeSerializable(_rssis);
}

private WifiAP(Parcel in) {
    _mac = in.readString();
    _mac2 = in.readString();
    _ssid = in.readString();

    if(in.readInt()==1)
        _dualband=true;
    else
        _dualband=false;

    _band = in.readInt();
    _band2 = in.readInt();
    _rssis = in.readSerializable(); // help here, this throws an error
}

您如何正确地从 Parcel.readSerializable 重新创建 ArrayList?

4

1 回答 1

6

尝试

   _rssis = (ArrayList<Integer>)  in.readSerializable();
于 2011-07-29T21:00:28.410 回答