What is the parameter for Parcel.readStringArray()?
android, parcelable
Solution
Here is an implementation of this method from Android 4.1.2:
public final void readStringArray(String[] val) {
int N = readInt();
if (N == val.length) {
for (int i=0; i<N; i++) {
val[i] = readString();
}
} else {
throw new RuntimeException("bad array lengths");
}
}
So it writes values to given array. And returns nothing.
Problem
I am trying to save the state in my `Fragment` through the use of `Parcelable`. This lead to the following code when I wish to get back the a String array that I saved in the Parcelable: ``` public MyObject createFromParcel(Parcel in) { titles=in.readStringArray(???); } ``` Now `readStringArray` needs a parameter, a `String[]`... But why? It could just give the Strings that I stored in it. I don't know a priori how many there were, so this sucks. :( The documentation says the following: `` That is, nothing. EDIT: If anyone has the same problem: I ended up using `writeBundle()`/`readBundle()` and putting my `String[]` into the `Bundle`.