2012-06-26 2 views
-1

가능한 중복 : 나는 어제이 작업을 얻었다
Can't pass an ArrayList<Parcelable> to an activity널 수신 Parcelable

, 나는 코드의 일부 다시 구성했다 지금은 일이 더 이상 작동하지 않습니다. 잠시 그것을 보니 문제가 발견되지 않습니다.

나는 활동에 Parcelables의 ArrayList를 전달 해요 :

ArrayList<MyParcelable> myArrayListOfParcelables = new ArrayList<MyParcelable>(); 

//... 

Intent intent = new Intent(this, ChooseGiftDetailsActivity.class); 
intent.putParcelableArrayListExtra(Constants.FOO, myArrayListOfParcelables); 
startActivity(intent); 

수신기 : 나는 하나를 보내고있다하더라도

ArrayList<Parcelable> parcelableList = (ArrayList<Parcelable>)getIntent().getParcelableArrayListExtra(Constants.FOO); 

parcelableList는 항상 null입니다.

MyParcelable은 물론 Parcelable을 확장합니다. 이미 putExtra를 사용 MyParcelable의 통과 하나 개의 객체를 테스트 항상 작동합니다

Parcelable p = (Parcelable)getIntent().getExtras().getParcelable(Constants.BAR); 

또는

MyParcelable p = (MyParcelable)getIntent().getExtras().getParcelable(Constants.BAR); 

내가 MyParcelable의 코드 일부 디버그 메시지를 넣어에만을 writting 방법이 목록을 통과 할 때, 나는 참조 실행했지만 결코 읽기 시작하지 않으며 심지어 createFromParcel도 실행되지 않습니다. 이게 뭐야?

+0

http://prasanta-paul.blogspot.com/2010/06/android-parcelable-example.html – Akram

+0

나는 그것을했지만 작동하지 않는다 – Ixx

+0

그 (것)들 당신은 무언가를 놓치게해야한다 – Akram

답변

0

작성자가 있다고 가정합니다. 작성하지 않은 경우 작성하십시오. 그럼 이런 식으로 그것을 시도 할 것 :

ArrayList<MyParcelable> myArrayListOfParcelables = new ArrayList<MyParcelable>(); 

//... 

Intent intent = new Intent(this, ChooseGiftDetailsActivity.class); 
intent.putIntExtra(Constants.FOO_COUNT, myArrayListOfParcelables.size()); 
MyParcelable p; 
for (int i = 0; i < myArrayListOfParcelables.size(); i++){ 
    p = myArrayListOfParcelables.get(i); 
    intent.putParcelableExtra(Constants.FOO + "_" + i, p); 
} 
startActivity(intent); 

가 다시 같이 읽어 :

Intent intent = getIntent(); 
int cnt = intent.getIntExtra(Constants.FOO_COUNT); 
ArrayList<MyParcelable> myArrayListOfParcelables = new ArrayList<MyParcelable>(cnt); 
MyParcelable p; 
for (int i = 0; i < cnt; i++){ 
    p = (MyParcelable)intent.getParcelableExtra(Constants.FOO + "_" + i); 
    myArrayListOfParcelables.add(p); 
} 

당신이 후드 세드릭 더 잘 볼 수있는의 abillity이이 방법. Parcelable의 배열이 너무 커서 Parceled를 얻을 수없는 경우가 있습니다. 한 번 Bitmap 전달하고 비슷한 문제가 있습니다.

+0

흠 ... 좋아, 이건 내가 시도 할 다음 일이 될거야. – Ixx