Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: How to implement Parcelable to my objects?
    text
    copied!<p>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.</p> <p>My question is, how should I declare the object within my class here and put every object inside a variable?</p> <p>I'm a newbie and I'm totally clueless right now. Thank you. Feel free to modify my code below.</p> <p><strong>ConstantData.java</strong></p> <pre><code>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&lt;Project&gt; projectsList = new ArrayList&lt;Project&gt;(); 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&lt;ConstantData&gt; CREATOR = new Parcelable.Creator&lt;ConstantData&gt;() { 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(); } } </code></pre> <p>In case my question is not clear enough, you can look up this question: <a href="https://stackoverflow.com/questions/2139134/how-to-send-an-object-from-one-android-activity-to-another-with-intent-putextra/2141166#2141166">How to send an object from one Android Activity to another using Intents?</a></p> <p>There he wrote <code>myParcelableObject</code>, I just don't know how to make the parcelable object.</p> <p><strong>EDIT</strong> <strong>Project.java</strong> </p> <pre><code>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; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload