Skip Arraylist Objects in Other Activities

I am trying to send a list of objects in another activity. I checked a lot of articles on this topic and I use parsing, but I am stuck at the point where I cannot send the object. I have tried many things. This is what I'm trying.

public class ParcalableForm implements Parcelable {

private ArrayList<form> from;


public ParcalableForm (ArrayList<form> choices) {
    this.from = choices;
}

public ParcalableForm (Parcel parcel) {
    this.from = parcel.readArrayList(null);
}



@Override
public int describeContents() {
    return 0;
}

// Required method to write to Parcel
@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeList(from);
}

// Method to recreate a Question from a Parcel
public static Creator<ParcalableForm> CREATOR = new Creator<ParcalableForm>() {

    @Override
    public ParcalableForm createFromParcel(Parcel source) {
        return new ParcalableForm(source);
    }

    @Override
    public ParcalableForm[] newArray(int size) {
        return new ParcalableForm[size];
    }

};

}

This is a class that implements Parcelable. I am trying to submit an Arraylist form to another action.

  Intent i = new Intent(UserPage.this,Form.class);

  Bundle extras = new Bundle();
  System.out.println("I found a form :- ");
  ParcalableForm p=new ParcalableForm(f1.attr);
  i.putExtra("geopoints", p);
  startActivity(i);

This is a class that sends an object to another action.

Bundle extras = getIntent().getExtras();
ParcalableForm po =  new ParcalableForm(extras.getParcelableArrayList("geopoints"));

This is the part where I do not know how to get the object / Arraylist. I tried many methods, but no luck. Any ideas?

0
source share
2 answers

Data transmission on anther activity

 ArrayList<Animal> animals = new ArrayList<Animal>();
//fill your list with animals here

i.putExtra("animals", animals);

Getting this data

ArrayList<Animal> animals = (ArrayList<Animal>) getIntent()
                        .getSerializableExtra("animals");
0
source

ArrayList<Form>, getParcelableArrayListExtra .
, :

  • Form Parcelable
  • :

    // ArrayList<Form> myList - data to send; intent.putParcelableArrayListExtra("geopoints", myList);

  • :

    ArrayList<Form> myReceivedList = getIntent().getParcelableArrayListExtra("geopoints");

/.

,

0

Source: https://habr.com/ru/post/1615939/


All Articles