Activity 간 객체 전달 방법
Parcel을 이용한 객체를 전달하는 방법을 통해
1. 전달하고자 하는 객체 클래스를 Parcelable 인터페이스를 구현한다.
import android.os.Parcel; import android.os.Parcelable; public class CategoryItem implements Parcelable { public String URL; public String Subject; @Override public int describeContents() { // TODO Auto-generated method stub return 0; } @Override public void writeToParcel(Parcel arg0, int arg1) { // TODO Auto-generated method stub arg0.writeString(URL); arg0.writeString(Subject); } public static final Parcelable.CreatorCREATOR = new Creator () { public CategoryItem createFromParcel(Parcel source) { CategoryItem category = new CategoryItem(); category.URL = source.readString(); category.Subject = source.readString(); return category; } public CategoryItem[] newArray(int size) { return new CategoryItem[size]; } }; }
전달시
Intent intent = new Intent(this, AllCategoryActivity.class); intent.putParcelableArrayListExtra("GetCategoryItem", mAllCategory); startActivity(intent);사용시
Bundle bundle = getIntent().getExtras(); mAllCategory = bundle.getParcelableArrayList("GetCategoryItem");
'Programming > 안드로이드' 카테고리의 다른 글
패키지명으로 어플 실행하기 (0) | 2011.06.23 |
---|---|
[안드로이드] 토스트(Toast) 팝업 구현 (0) | 2010.09.05 |