To transfer the string from the activation to the fragment, created the class class MyObject implements Parcelable. Strings are perfectly passed, but with an array, an error occurs, more correctly emphasizes the brackets readArray (). I understand that you need to write something in brackets or you may not use readArray () at all

Below all the code

public class MyObject implements Parcelable { public String paramBuk; public String[] paramImya; public MyObject(String paramBuk, String[] paramImya) { this.paramBuk = paramBuk; this.paramImya = paramImya; } private MyObject(Parcel parcel) { // Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Π° Ρ‡Π΅Ρ€Π΅Π· Parcel paramBuk = parcel.readString(); paramImya = parcel.readArray(); } public int describeContents() { return 0; } public void writeToParcel(Parcel parcel, int flags) { //Π£ΠΏΠ°ΠΊΠΎΠ²Ρ‹Π²Π°Π½ΠΈΠ΅ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Π° Π² Parcel parcel.writeString(paramBuk); parcel.writeArray(paramImya); } public static final Parcelable.Creator<MyObject> CREATOR = new Parcelable.Creator<MyObject>() { // БтатичСский ΠΌΠ΅Ρ‚ΠΎΠ΄ с ΠΏΠΎΠΌΠΎΡ‰ΡŒΡŽ ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ³ΠΎ создаСм ΠΎΠ±ΡŒΠ΅ΠΊΡ‚ public MyObject createFromParcel(Parcel in) { return new MyObject(in); } public MyObject[] newArray(int size) { return new MyObject[size]; } }; } 

public String paramBuk; - works great, accepts data and transmits

But with the public String [] paramImya; something is wrong, it emphasizes the brackets readArray ()

  • one
    I do not know for what purpose this huge crutch is being written, but humanly, the data are transferred from activations to a fragment like this - Silento

1 answer 1

To read from parcel you can use the command:

 paramImya = parcel.createStringArray(); 

And you can probably have a faster method, in which you need to know in advance the size N the paramImya array:

 paramImya = new String[N]; parcel.readStringArray(paramImya); 

And in paramImya will be stored read values.

The source shows that there is also a method readStringArray() , which for some reason is not listed in the documentation . You can try to use it as follows:

 paramImya = parcel.readStringArray(); 

Well, a write data in parcel you can command:

 parcel.writeStringArray(paramImya); 
  • Thank you, I have already found a solution using a spear method)) But everything was right through readStringArray - Artsait