问题描述
- 发送一个 arraylist 到 parent activity
-
我想发送一个 arraylist 到 parent activityprivate 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)
解决方案
public class Receipt implements Serializable{
public String referenceNo;
public byte[] image;
public String comments;
public long createdOn;
public long updatedOn;
//...
}
//Put the list in the intent
List<Receipt> list = ...
Intent data = new Intent();
data.putExtra("tag", list);
//Read the list from the intent:
list = (List<Receipt>) data.getSerializableExtra("tag");
解决方案二:
Receipt extends Parcelable才能传递
public void putParcelableArrayList(String key,
ArrayList<? extends Parcelable> value) {}
时间: 2024-10-26 05:53:31