다음 코드를 사용하여 개체를 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;
}
}
@ 사이먼 : U가 번들을 준비하고 코드를 사용하여 게시물을 편집 할 수 있습니까? Serialazable –
에 코드를 추가하면 – Simon
이 클래스에 Serialazable을 구현합니다. –