次のコードを使用してオブジェクトをシリアル化し、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;
}
}
@Simonは:uはuがSerialazable –
バンドルを準備して実装されているコードを使用して投稿を編集することができます – Simon
uは必ずあなたのクラス –