2

I'm doing this course on Udacity(Final Project Stage 1) and I need to make a Popular Movies app. All is well but currently I am unable to pass the Movie object to my DetailsActivity. The Movie object is Parcelable.

    public class Movie implements Parcelable{

    int id;
    String original_title;
    String poster_path;
    String overview;
    String backdrop_path;
    String vote_average;
    String release_date;

    public Movie(String _original_title, String _poster_path,
                 String _overview, String _backdrop_path,
                 String _vote_average, String _release_date, int _id){
        this.original_title = _original_title;
        this.id = _id;
        this.overview = _overview;
        this.poster_path = _poster_path;
        this.backdrop_path = _backdrop_path;
        this.vote_average = _vote_average;
        this.release_date = _release_date;
    }

    protected Movie(Parcel in) {
        id = in.readInt();
        original_title = in.readString();
        overview = in.readString();
        poster_path = in.readString();
        backdrop_path = in.readString();
        vote_average = in.readString();
        release_date = in.readString();
    }

    public static final Creator<Movie> CREATOR = new Creator<Movie>() {
        @Override
        public Movie createFromParcel(Parcel in) {
            return new Movie(in);
        }

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

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

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(original_title);
        dest.writeString(overview);
        dest.writeString(poster_path);
        dest.writeString(backdrop_path);
        dest.writeString(vote_average);
        dest.writeString(release_date);
        dest.writeInt(id);
    }
}

And I'm using the following code to send and retrieve data between Activities.

MainActivityFragment.java

Movie mData = mMovieAdapter.getItem(position);
            Log.d("Backdrop Path", mData.backdrop_path+""); // Backdrop Path : http://image.tmdb.org/t/p/w185/m5O3SZvQ6EgD5XXXLPIP1wLppeW.jpg

            Bundle movieData = new Bundle();
            movieData.putParcelable(KEY_DETAIL, mData);

            Intent intent = new Intent(getActivity(), MovieDetailActivity.class);
            intent.putExtras(movieData);
            startActivity(intent);

MovieDetailActivityFragment.java

Bundle data = getActivity().getIntent().getExtras();
    if(data != null)
        movie = data.getParcelable(KEY_DETAIL);  //Movie object

    Log.d("Loading Image", movie.backdrop_path+"");  // Loading Image : null

So as per the logs, I'm sure that the Movie object being Bundled has data. But when I retrieve the object in the other class, the object is not null, but the data members are.

helios_xt
  • 87
  • 8

1 Answers1

0

For me the solution was changing the read/write method to read/write every object memeber in the same order.

Regards

tiagocarvalho92
  • 375
  • 1
  • 7
  • 17
  • Please remove this and use comments instead as your post is NOT an answer _I don't know why this happens_ – B001ᛦ Jan 27 '17 at 09:54
  • 1
    I had the same problem as this user and with this ( Read in the order as you write to te parcel ) did fix the problem. So for me it's a answer to the user problem – tiagocarvalho92 Jan 27 '17 at 13:41