I have this ConstantData class which holds my JSON indexes, I need to pass them between activities with extras. But before that, I have to implement Parcelable to the objects of this class first.
My question is, how should I declare the object within my class here and put every object inside a variable?
I'm a newbie and I'm totally clueless right now. Thank you. Feel free to modify my code below.
ConstantData.java
public class ConstantData{
public static String project_title = "project title";
public static String organization_title = "organization title";
public static String keyword = "keyword";
public static String short_code = "short code";
public static String project_description = "description";
public static String smallImageUrl = "smallImageUrl";
public static String bigImageUrl = "bigImageUrl";
public static String price= "price";
public static String country= "country";
public static ArrayList<Project> projectsList = new ArrayList<Project>();
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel out, int flags) {
out.writeString(project_title);
out.writeString(organization_title);
out.writeString(keyword);
out.writeString(short_code);
out.writeString(project_description);
out.writeString(smallImageUrl);
out.writeString(bigImageUrl);
out.writeString(price);
out.writeString(country);
}
public static final Parcelable.Creator<ConstantData> CREATOR
= new Parcelable.Creator<ConstantData>() {
public ConstantData createFromParcel(Parcel in) {
return new ConstantData(in);
}
public ConstantData[] newArray(int size) {
return new ConstantData[size];
}
};
private ConstantData(Parcel in) {
project_title = in.readString();
organization_title = in.readString();
keyword = in.readString();
short_code = in.readString();
project_description = in.readString();
smallImageUrl = in.readString();
bigImageUrl = in.readString();
price = in.readString();
country = in.readString();
}
}
In case my question is not clear enough, you can look up this question: How to send an object from one Android Activity to another using Intents?
There he wrote myParcelableObject
, I just don't know how to make the parcelable object.
EDIT Project.java
public class Project {
public String project_title;
public String organization_title;
public String keyword;
public String short_code;
public String project_description;
public String smallImageUrl;
public String bigImageUrl;
public String price;
public String country;
}