![](/img/trans.png)
[英]How to pass object from one activity to another activity without using Intent
[英]How to pass ArrayList<File> object from one Activity to another Activity using Intent?
我有一個ArrayList文檔,我想將此文件發送到另一個Activity。 但是如何在SecondActivity中獲得此值
我嘗試的是首次活動
private ArrayList<File> documents;
Intent selectLabInt = new Intent(FirstActivity.this, SecondActivity.class);
selectLabInt.putExtra("patient_name", patientNameStr);
selectLabInt.putExtra("referal_notes", referalNotesStr);
selectLabInt.putExtra("fileList",documents);
startActivity(selectLabInt);
如果您的File
可序列化,則可以像這樣傳遞ArrayList
:
在發送活動中:
ArrayList<File> documents= new ArrayList<File>();
intent.putExtra("documents", documents);
在接收活動中:
ArrayList<File> documents = (ArrayList<File>)getIntent().getSerializableExtra("documents");
您需要使File類可拆分,以便可以通過putParcelable故意傳遞該類的arraylist。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.