I know there have been a lot of questions on this topic but I can't find an answer for my specific case. Basically I have a two dimensional array of a fairly simple class that I need to pass. I am trying to use Parcelable
and I ran my class through this to get this:
import android.os.Parcel;
import android.os.Parcelable;
public class Notam implements Parcelable {
public String airfield;
public String identifier;
public String notamText;
public String fromTime;
public String untilTime;
public boolean hidden;
// one constructor
public Notam(String airfieldname, String newIdentifier, String newNotamText, String newFrom, String newUntil) {
airfield = airfieldname;
identifier = newIdentifier;
notamText = newNotamText;
fromTime = newFrom;
untilTime = newUntil;
}
public void setHidden(boolean changeHidden) {
hidden = changeHidden;
}
protected Notam(Parcel in) {
airfield = in.readString();
identifier = in.readString();
notamText = in.readString();
fromTime = in.readString();
untilTime = in.readString();
hidden = in.readByte() != 0x00;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(airfield);
dest.writeString(identifier);
dest.writeString(notamText);
dest.writeString(fromTime);
dest.writeString(untilTime);
dest.writeByte((byte) (hidden ? 0x01 : 0x00));
}
@SuppressWarnings("unused")
public static final Parcelable.Creator<Notam> CREATOR = new Parcelable.Creator<Notam>() {
@Override
public Notam createFromParcel(Parcel in) {
return new Notam(in);
}
@Override
public Notam[] newArray(int size) {
return new Notam[size];
}
};
}
I have tried all manner of things I found from here but I am now lost. At the moment in Main Activity I have
Notam[][] notamList = new Notam[10][100];
Intent intent = new Intent(this, NotamList.class);
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("notamList", notamList);
intent.putExtras(bundle);
startActivity(intent);
And then in the receiving activity:
Notam[][] notamList = new Notam[10][100];
Bundle data = getIntent().getExtras();
notamList = data.getParcelableArrayList("notamList");
But this is not even close to working so I ask for your wisdom and guidance!