2012-04-24 4 views
0

다음 코드를 사용하여 개체를 serialize하고 putSerializable을 통해 번들에 첨부 한 다음 Message를 통해 다른 프로세스로 번들을 보냅니다. 문제는 객체가 직렬화되지 않는다는 오류가 발생한다는 것입니다. 나는 "Serialazable 구현"을 추가하려고했지만 여전히 같은 오류가 발생합니다. 다른 프로세스에 번들 보내기

public static byte[] serializeObject(Object o) 
{ 
    ByteArrayOutputStream bos = new ByteArrayOutputStream(); 

    try { 
     ObjectOutput out = new ObjectOutputStream(bos); 
     out.writeObject(o); 
     out.close(); 

     // Get the bytes of the serialized object 
     byte[] buf = bos.toByteArray(); 

     return buf; 
    } catch(IOException ioe) { 
     Log.e("serializeObject", "error", ioe); 

     return null; 
    } 
    } 

는 전화를 걸 그 코드 :

   ArrayList<byte[]> blist=null; 
       Bundle b = new Bundle(); 
       if (TriggerList != null && TriggerList.size() > 0) 
       { 
        Iterator iter = TriggerList.iterator(); 
        while (iter.hasNext()) 
        { 
         Bundle entry = (Bundle) iter.next(); 
         if (msg.arg1 == entry.getInt(ProjDefs.APP_ID)) 
         { 
          if (blist == null) 
           blist=new ArrayList<byte[]>(); 
          SerBundle sb = new SerBundle(entry); 
          byte[] bb = serializeObject(sb); 
          blist.add(bb); 
         }  
        } 
        b.putSerializable(ProjDefs.SERIAL_DATA, blist); 
       } 
       NotifyClient(msg.arg1, ProjDefs.GET_APP_TRIGGERS_RESPONSE, 0, 0, b, null); 

직렬화 가능 클래스 :

공용 클래스 SerBundle 직렬화 {

/** 
* 
*/ 
private static final long serialVersionUID = 1L; 
public Bundle bundle; 

public SerBundle(Bundle bundle) 
{ 
    this.bundle = bundle; 
} 

}

+0

@ 사이먼 : U가 번들을 준비하고 코드를 사용하여 게시물을 편집 할 수 있습니까? Serialazable –

+0

에 코드를 추가하면 – Simon

+0

이 클래스에 Serialazable을 구현합니다. –

답변

0

를 구현 Bundle은 이미 Parcelable입니다. Bundle을 다른 Bundle 안에 값으로 넣을 수 있으며 ObjectOutputStream으로 뒤죽박죽하지 않아도됩니다.

+0

번들의 ArrayList도 둘 수 있습니까? – Simon

+0

@ Simon : 예 ['putParcelableArrayList()'] (http://goo.gl/5tpcg)를 사용하십시오. – CommonsWare

관련 문제