π Android μμ Intent λ₯Ό μ¬μ©νμ¬ λ°μ΄ν°λ₯Ό μ λ¬νκ³ μ ν λ, κ°μ²΄λ‘ μ λ¬ν΄μΌ ν κ²½μ°κ° μλ€. μ΄ λ λνμ μΈ λ°©λ²μ΄ Serializable κ³Ό Parcelable μ μ¬μ©νλ λ°©λ²μΈλ°, μ΄ μ€ Parcelable μ λν΄ μμ보μ.
Serializable μ΄λ μμ΄λ‘ λ²μνλ©΄ 'μ§λ ¬ν' λΌκ³ μ΄μΌκΈ°ν μ μλλ°, μ½κ² μ΄μΌκΈ°νλ©΄ λ°μ΄ν°λ₯Ό λ¬Άμ΄μ μ λ¬ν μ μκ² ν΄μ€λ€κ³ λ³Ό μ μλ€.
java μμ μ 곡ν΄μ£Όλ Serializable μ ꡬνν΄μΌν λ©μλκ° μμ΄ νΈλ¦¬νλ€.
λλ€λ₯Έ μ¬μ©λ²μΌλ‘λ Android Parcelable μλ€.
Parcelable μ μμ΄λ‘ λ²μνλ©΄ 'μν¬ κ°λ₯' μ΄λΌκ³ λ§ν μ μκ³ , μ΄κ² μμ μ¬λ¬ λ°μ΄ν°λ₯Ό λ΄μ μ λ¬νλ€κ³ λ³Ό μ μλ€.
Parcelable μ μ§λ ¬νμ μμ§λ ¬νλ₯Ό μ§μ ꡬνν΄μΌνλ€λ λ¨μ μ΄ μμ§λ§, μλκ° ν¨μ¬ λΉ λ₯΄λ€λ μ₯μ μ΄ μμ΄ Parcelable μ μ¬μ©νμλ€.
public class TestInfo implements Parcelable {
int id;
String name;
String testNumber;
public TestInfo(String name, String testNumber) {
this.name = name;
this.testNumber = testNumber;
}
}
public class TestInfo implements Parcelable {
int id;
String name;
String testNumber;
public TestInfo(int id, String name, String testNumber) {
this.id = id;
this.name = name;
this.testNumber = testNumber;
}
protected TestInfo(Parcel in) {
id = in.readInt();
name = in.readString();
testNumber = in.readString();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(id);
dest.writeString(name);
dest.writeString(testNumber);
}
@Override
public int describeContents() {
return 0;
}
public static final Creator<TestInfo> CREATOR = new Creator<TestInfo>() {
@Override
public TestInfo createFromParcel(Parcel in) {
return new TestInfo(in);
}
@Override
public TestInfo[] newArray(int size) {
return new TestInfo[size];
}
};
}
TestInfo testInfo = new TestInfo(1, "test1", 1);
Intent intent = new Intent(this, SecondActivity.class);
intent.putExtra("testInfo", testInfo);
TestInfo testInfo = getIntent().getParcelableExtra("testInfo");