发送一个 arraylist 到 parent activity

我想发送一个 arraylist 到 parent activity

private ArrayList<Receipt> receipts = new ArrayList<Receipt>();
 Intent data = new Intent();
 data. // what to do here?
setResult(RESULT_OK, data); 
//************************************

下面是简单的代码

public class Receipt {
    public String referenceNo;
    public byte[]   image;
    public String comments;
    public Date   createdOn;
    public Date   updatedOn;

如何在 intent 中添加,还有如何从 parent activity 里检索?

onActivityResult(final int requestCode, int resultCode, final Intent data)


慕桂英3389331
浏览 513回答 2
2回答

扬帆大鱼

public&nbsp;class&nbsp;Receipt&nbsp;implements&nbsp;Serializable{ &nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;String&nbsp;referenceNo; &nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;byte[]&nbsp;&nbsp;&nbsp;image; &nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;String&nbsp;comments; &nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;long&nbsp;&nbsp;&nbsp;createdOn; &nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;long&nbsp;&nbsp;&nbsp;updatedOn; &nbsp;&nbsp;&nbsp;&nbsp;//... } //Put&nbsp;the&nbsp;list&nbsp;in&nbsp;the&nbsp;intent List<Receipt>&nbsp;list&nbsp;=&nbsp;... Intent&nbsp;data&nbsp;=&nbsp;new&nbsp;Intent(); data.putExtra("tag",&nbsp;list); //Read&nbsp;the&nbsp;list&nbsp;from&nbsp;the&nbsp;intent: list&nbsp;=&nbsp;(List<Receipt>)&nbsp;data.getSerializableExtra("tag");

梦里花落0921

Receipt extends Parcelable才能传递public&nbsp;void&nbsp;putParcelableArrayList(String&nbsp;key, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ArrayList<?&nbsp;extends&nbsp;Parcelable>&nbsp;value)&nbsp;{}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java