Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8707467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:52:42+00:00 2026-06-13T03:52:42+00:00

I have an object in the form public class Car implements Serializable, Parcelable {

  • 0

I have an object in the form

public class Car implements Serializable, Parcelable {

    private static final long serialVersionUID = 1L;

    String name;
    String description;
    String brand;
    int speed;
    int brake;
    int asset;
    ArrayList<Uri> images;

    public Car(String name, String description, String brand, int speed,
            int brake, int asset, ArrayList<Uri> images) {
        super();
        this.name = name;
        this.description = description;
        this.brand = brand;
        this.speed = speed;
        this.brake = brake;
        this.asset = asset;
        this.images = images;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public int getBrake() {
        return brake;
    }

    public void setBrake(int brake) {
        this.brake = brake;
    }

    public int getAsset() {
        return asset;
    }

    public void setAsset(int asset) {
        this.asset = asset;
    }

    public ArrayList<Uri> getImages() {
        return images;
    }

    public void setImages(ArrayList<Uri> images) {
        this.images = images;
    }

    public static long getSerialversionuid() {
        return serialVersionUID;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + asset;
        result = prime * result + brake;
        result = prime * result + ((brand == null) ? 0 : brand.hashCode());
        result = prime * result
                + ((description == null) ? 0 : description.hashCode());
        result = prime * result + ((images == null) ? 0 : images.hashCode());
        result = prime * result + ((name == null) ? 0 : name.hashCode());
        result = prime * result + speed;
        return result;
    }

    @Override
    public String toString() {
        return "Car [name=" + name + ", description=" + description
                + ", brand=" + brand + ", speed=" + speed + ", brake=" + brake
                + ", asset=" + asset + ", images=" + images + "]";
    }

    public int describeContents() {
        // TODO Auto-generated method stub
        return 0;
    }

    public void writeToParcel(Parcel dest, int flags) {
        // TODO Auto-generated method stub

    }




}

But I haven’t understand how to implements

public void writeToParcel(Parcel dest, int flags) {
    // TODO Auto-generated method stub

}

and

public int describeContents() {
    // TODO Auto-generated method stub
    return 0;
}

that Eclipse have required after the adding of implements Parcelable to the class

on the Android site the sample show also a method

  public static final Parcelable.Creator<MyParcelable> CREATOR
             = new Parcelable.Creator<MyParcelable>() {
         public MyParcelable createFromParcel(Parcel in) {
             return new MyParcelable(in);
         }

What is the right way to make my whole class (and all the nested objects as ArrayList) “Parcelable”?

following the sample I’m arrived to the constructor

public Car(Parcel in) {
   name= in.readString();
 description= in.readString();
speed=in.readInt();
...

images=in.readArrayList(??????????????????);
}

what is the Class loader to pass in readArrayList(..)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:52:43+00:00Added an answer on June 13, 2026 at 3:52 am

    On the writeToParcel method you should do:

    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(brand); //To write String
    }
    

    The argument dest in the writeToParcel method has a lot of other methods to write other object or raw types.
    To put other objects that do not have specific methods in the dest object, you should use the methods writeParcelable if the object you are trying to write implements Parcelable or writeSerializable if the object you are trying to write implements Serializable.

    After, when you’ll recover your Parceable object, you should use:

    private void readFromParcel(Parcel in) {
        brand = in.readString(); //To read String
    }
    

    You have to read the values from the in object in the same order you wrote them.

    The piece of code:

    public static final Parcelable.Creator<Car> CREATOR = new Parcelable.Creator<Car>() {
             public Car createFromParcel(Parcel in) {
                 return new Car(in);
             }
    }
    

    Is necessary to call the readFromParcel method. You should add in your class a constructor to be called from the piece of code above.
    The constructor should look like:

    public Car(Parcel in) {
       readFromParcel(in);
    }
    

    About the method describeContents, there is a good answer on Stackoverflow, here.

    Summarizing, I’ve never seen any case in which this method was used. The method is used if you want to release resources after the parsing of the Parcel, but I didin’t found any good material on the internet explaining it. Chances are that you’ll keep it returning 0.
    You can found Android documentation for it here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have the form object like this: public class FormData {
I have a user defined class, say import java.util.Calendar; public class Employee{ private String
I have a command object associated with a spring form controller: public class PluginInstance
I have one debugger visualizer for seeing list of class object in the form
I have created a class Car that derives form the abstract class TransportMeans and
I have the following business object: public class MyObject { // Some public properties
Suppose I have one class Person ……… public class Person { public string Name
public partial class Form1 : Form { public disp(string strVal) { lbl1.text = strVal;
I have this class: Public Class common Public Function NumbersOnlyEvent(ByVal CtrlName As String, ByVal
I have Form and Class like that : namespace ALTER_Control { public partial class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.