Android調用遠程Service的參數和傳回值都需要實現Parcelable介面

來源:互聯網
上載者: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;
  }

  //實現Parcelable介面必須實現的方法
  @Override
  public int describeContents() {
    return 0;
  }

  //實現Parcelable介面必須實現的方法
  @Override
  public void writeToParcel(Parcel dest, int flags) {
    //把該對象所包含的資料寫到Parcel
    dest.writeInt(id);
    dest.writeString(name);
    dest.writeString(pass);
  }

  //添加一個靜態成員,名為CREATOR。該對象實現了Parcelable.Creator介面
  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) {
      // 從Parcel中讀取資料,返回Person對象
      return new Person(source.readInt(),
          source.readString(), source.readString());
    }
  };

}

Android調用遠程Service的參數和傳回值都需要實現Parcelable介面

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.