안드로이드 개발 질문/답변
(글 수 45,052)
ublic class Test implements Parcelable{
private int myInt = 0;
private String myStr = "";
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel out, int flags) {
out.writeInt(myInt);
out.writeString(myStr);
}
public static final Parcelable.Creator<Test> CREATOR = new Parcelable.Creator<Test>() {
public Test createFromParcel(Parcel in) {
int x = in.readInt();
String y = in.readString();
return new Test(x, y);
}
public Test[] newArray(int size) {
return new Test[size];
}
};
Test(int x, String y) {
myInt = x;
myStr = y;
}
}
Intent i = new Intent(this, RcvIntentActivity.class);
i.putExtra("test", test);
startActivity(i);이렇게 액티비티 A에서 인텐트를 담아서 보냈습니다..
그리고 액티비티 B에서 받아서 처리하려고 하는데..
Bundle b = new Bundle();
b = getIntent().getParcelableExtra("test");
Test t = new Test();
t = getIntent().getParcelableExtra("test");이렇게 번들에 받아서도 해보고.. Test객체를 새로 생성해서도 넣어보고 했는데요..
받아온 객체의 멤버변수(myInt, myStr)에 접근할 방법을 모르겠네요 ㅠㅠ
틀린부분이 있는지, 그리고 parcel을 받아서 쓰는부분에서 어떻게 해야하는지 조언좀 부탁드립니다 ㅠㅠ