- First serialize the object you want to pass.
- Place the serialization object in advanced settings.
- At the end of the reception, just get the serialized object, deserialize it.
eg,
Employee employee = new Employee();
then
intent.putExtra("employee", serializeObject(employee));
upon admission
byte[] sEmployee = extras.getByteArray("employee");
employee = (Employee) deserializeObject (sEmployee);
FYI,
public static byte[] serializeObject(Object o) throws Exception,IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(bos); try { out.writeObject(o); // Get the bytes of the serialized object byte[] buf = bos.toByteArray(); return buf; } catch (IOException e) { Log.e(LOG_TAG, "serializeObject", e); throw new Exception(e); } finally { if (out != null) { out.close(); } } } public static Object deserializeObject(byte[] b) throws StreamCorruptedException, IOException, ClassNotFoundException, Exception { ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream(b)); try { Object object = in.readObject(); return object; } catch (Exception e) { Log.e(LOG_TAG, "deserializeObject", e); throw new Exception(e); } finally { if (in != null) { in.close(); } } }
source share