본문 바로가기

Development/Android

[Android] intent로 Object 전달하기~!

전달할 객체를 Parcelable 인터페이스를 상속 받아서 아래와 같이 구현을 한다.


절대로 write와 Read순서는 항상 동일~!!!!!!! 절대 중요~!!!


public class ReceivedDateDao implements Parcelable {


public ReceivedDateDao () {

}//end constructor

public ReceivedDateDao (final Parcel in) {

this.readFromParcel(in);

}//end constructor

@Override

public int describeContents() {

return 0;

}//end describeContents Method


@Override

public void writeToParcel(Parcel dest, int flags) {

dest.writeParcelable(this.mUserDao, 0);

dest.writeString(this.mType);

dest.writeString(this.mStoreId);

dest.writeString(this.mCreated);

dest.writeString(this.mMessage);

dest.writeInt(this.mIsNew);

dest.writeInt(this.mWhoSend);

}//end writeToParcel Method

private void readFromParcel (final Parcel in) {

this.mUserDao = in.readParcelable(UserDao.class.getClassLoader());

this.mType = in.readString();

this.mStoreId = in.readString();

this.mCreated = in.readString();

this.mMessage = in.readString();

this.mIsNew = in.readInt();

this.mWhoSend = in.readInt();

}//end readFromParcel Mehod



public static final Parcelable.Creator<ReceivedDateDao> CREATOR = new Creator<ReceivedDateDao>() {

public ReceivedDateDao createFromParcel(Parcel source) {

return new ReceivedDateDao(source);

        }//end createFromParcel Method

        public ReceivedDateDao[] newArray(int size) {

            return new ReceivedDateDao[size];

        }//end newArray Method

        

};