7

In my project, I have to write and read ArrayList<String> to parcel, I tried with writeList and writeStringList but no use, I am getting exceptions while reading the lists.

Could any one help me in this?

Thanks In advance.

Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
  • Hi Your question is not clear but if you want to read/write an ArrayList here's a way To read an ArrayList you need a for each loop ArrayList list=new ArrayList(); for(String str: list){ //do something here with the str } – cafebabe1991 Apr 25 '13 at 05:04
  • 1
    Post some code that you have tried so far. – Paresh Mayani Apr 25 '13 at 05:07
  • Post your code and logcat details .check this http://idlesun.blogspot.in/2012/12/android-parcelable-example-2-subobject.html – edwin Apr 25 '13 at 05:09
  • 1
    Need more detail in this question. `writeStringList`, `readStringList` and `createStringArrayList` are the methods you probably want. – Jeremy Roman Apr 25 '13 at 05:09
  • http://stackoverflow.com/a/7400675/726863 – Lalit Poptani Apr 25 '13 at 05:11

2 Answers2

8

By @JeremyRoman: writeStringList, readStringList and createStringArrayList all exist on Parcel since API 1.

StoneBird
  • 1,900
  • 13
  • 12
  • 4
    `writeStringList`, `readStringList` and `createStringArrayList` all exist on [`Parcel`](http://developer.android.com/reference/android/os/Parcel.html) since API 1. – Jeremy Roman Apr 25 '13 at 05:11
  • @JeremyRoman Correct. I might need a good sleep before continuing to answer questions. Thanks for correcting me. – StoneBird Apr 25 '13 at 05:15
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – Baby Groot Apr 25 '13 at 05:31
  • @HinataHyuga I edited my answer. My previous answer was incorrect. Check revisions so you know. Thanks. – StoneBird Apr 25 '13 at 05:32
  • @StoneBird Put answer in your post not in your comment. – Baby Groot Apr 25 '13 at 05:36
  • @HinataHyuga That's not my answer. – StoneBird Apr 25 '13 at 05:37
  • @StoneBird Whatever is your correct answer. Edit your post and put correct answer there. – Baby Groot Apr 25 '13 at 05:38
  • Hi thanks everybody,I used writeStringList for writing to stringlist to parcel and while reading I forgot to intialise the arraylist object to while the read value to assign – Gopika Perumalla May 06 '13 at 06:55
  • Please correct your answer. Or atleast provide steps to use the said methods. Else delete the answer and add it as a comment. – Zen Mar 05 '16 at 14:51
1

use this to write:

bundle.putStringArrayList(KEY, stringArrayList); 

and this to read:

ArrayList<String> stringArrayList = bundle.getStringArrayList(KEY);