There is a film class

public class Film implements Parcelable{ private String filmName; private String filmImage; private String filmDate; public Film(String filmName, String filmImage, String filmDate) { this.filmName = filmName; this.filmImage = filmImage; this.filmDate = filmDate; } public String getFilmName() { return filmName; } public String getFilmImage() { return filmImage; } public String getFilmDate() { return filmDate; } private Film(Parcel in) { filmName = in.readString(); filmImage = in.readString(); filmDate = in.readString(); } public static final Creator<Film> CREATOR = new Creator<Film>() { @Override public Film createFromParcel(Parcel in) { return new Film(in); } @Override public Film[] newArray(int size) { return new Film[size]; } }; @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel parcel, int i) { parcel.writeString(filmName); parcel.writeString(filmImage); parcel.writeString(filmDate); } } 

Trying to pass an ArrayList from one fragment to another by calling

 mFragmentTransaction.replace(R.id.fragment_container, FilmsFragment.newInstance(mFilmList,"DC Films")).addToBackStack("choose").commit(); 

in onclick here is the newInstance method

  public static FilmsFragment newInstance(ArrayList<Film> filmList, String title) { FilmsFragment fragment = new FilmsFragment(); Bundle args = new Bundle(); args.putParcelableArrayList(ARG_PARAM_FILMS, filmList); args.putString(ARG_PARAM_FILMS, title); fragment.setArguments(args); return fragment; } 

I receive so in OnCreate

  if (getArguments() != null) { mFilmList = getArguments().getParcelableArrayList(ARG_PARAM_FILMS); mTitle = getArguments().getString(ARG_PARAM_TITLE); } 

but after

getParcelableArrayList ()

and

getString ()

getting null. when passing all the rules, in the previous fragment, but after receiving from getArguments, I get null. What is the error in the implementation of Parcelable?

  • one
    You put the arguments in the fragment one by one tag. - temq

1 answer 1

It looks like you confused the parameter keys. In newInstance instead

 args.putString(ARG_PARAM_FILMS, title); 

must be

 args.putString(ARG_PARAM_TITLE, title); 
  • Yes, thanks, I wrote the code at 5 am, the brain didn’t cook any more, it was a very stupid mistake. - newakkoff