简体   繁体   中英

Pass ArrayList of Arrays (e.g. ArrayList<String[]>) to Intent

How do I pass an ArrayList of arrays to an intent in Android? I know you can pass an ArrayList<String> , but is it possible to pass an ArrayList<String[]> ?

It's possible, but you need to pass it as a Serializable and you'll need to cast the result when you extract the extra. Since ArrayList implements Serializable and String[] is inherently serializable, the code is straightforward. To pass it:

ArrayList<String[]> list = . . .;
Intent i = . . .;

i.putExtra("strings", list);

To retrieve it:

Intent i = . . .;
ArrayList<String[]> list = (ArrayList<String[]>) getSerializableExtra("strings");

You'll have to suppress (or live with) the unchecked conversion warning.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM