Android calls remote service parameters and return values are required to implement the Parcelable interface

Source: Internet
Author: User

Import Android.os.Parcel;
Import android.os.Parcelable;

public class person implements parcelable{
Private Integer ID;
private String name;
Private String Pass;

Public person () {
Super ();
}

Public person (Integer ID, string name, String pass) {
Super ();
This.id = ID;
THIS.name = name;
This.pass = pass;
}

Public Integer getId () {
return ID;
}

public void SetId (Integer id) {
This.id = ID;
}

Public String GetName () {
return name;
}

public void SetName (String name) {
THIS.name = name;
}

Public String Getpass () {
return pass;
}

public void SetPass (String pass) {
This.pass = pass;
}

@Override
public int hashcode () {
final int prime = 31;
int result = 1;
result = Prime * result + ((name = = null)? 0:name.hashcode ());
result = Prime * result + ((pass = = null)? 0:pass.hashcode ());
return result;
}

@Override
public boolean equals (Object o) {
if (this = = O) {
return true;
}
if (o = = null) {
return false;
}
if (getclass () = O.getclass ()) {
return false;
}
person other = (person) o;
if (name = = null) {
if (other.name! = null) {
return false;
}
}else if (!name.equals (Other.name)) {
return false;
}
if (pass = = null) {
if (other.pass! = null) {
return false;
}
}else if (!pass.equals (Other.pass)) {
return false;
}
return true;
}

Methods to implement the Parcelable interface
@Override
public int describecontents () {
return 0;
}

Methods to implement the Parcelable interface
@Override
public void Writetoparcel (Parcel dest, int flags) {
Write the data contained in the object to parcel
Dest.writeint (ID);
Dest.writestring (name);
Dest.writestring (pass);
}

Add a static member named Creator. The object implements the Parcelable.creator interface
public static final Parcelable.creator<person> Creator
= new Parcelable.creator<person> () {

@Override
Public person[] NewArray (int size) {
return new Person[size];
}

@Override
Public person Createfromparcel (Parcel source) {
Reads data from parcel, returns the person object
return new Person (Source.readint (),
Source.readstring (), source.readstring ());
}
};

}

Android calls remote service parameters and return values are required to implement the Parcelable interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.