0

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[]>?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.