여기서는 Extras에 Java 클래스를 넣어 정보 교환을 해 보자.
음, 점심시간에 잠깐 하려고 했더니 누가 와서 업무 관련 문의를 해서 점심 시간을 오버 했다. 아래 정리도 좀 부실해 졌군.
*정보를 교환할 클래스는 반드시 Serializable 해야 한다.
public class Contact implements Serializable {
}
*정보 전달
ByteArrayOutputStream bos = null;
ObjectOutputStream oos = null;
Intent intent = new Intent(getApplicationContext(), ContactEditActivity.class);
try {
bos = new ByteArrayOutputStream(1024 * 100);
oos = new ObjectOutputStream(bos);
oos.writeObject(contact);
oos.close();
} catch (IOException e) {
e.printStackTrace();
return;
}
intent.putExtra("contact", bos.toByteArray());
startActivity(intent);
*정보 수신
Contact contact = null;
byte[] contactStream = null;
ByteArrayInputStream bis = null;
ObjectInputStream ois = null;
Intent intent = getIntent();
contactStream = intent.getExtras().getByteArray("contact");
try {
bis = new ByteArrayInputStream(contactStream);
ois = new ObjectInputStream(bis);
contact = (Contact) ois.readObject();
ois.close();
} catch (StreamCorruptedException e) {
e.printStackTrace();
return;
}
*** 참고 문헌 ***
Posted by 산사랑

