android - getParcelable() returns object with null data members for Parcelable object -
i'm doing course on udacity(final project stage 1) , need make popular movies app. unable pass movie object detailsactivity. movie object 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 following code send , 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 per logs, i'm sure movie object being bundled has data. when retrieve object in other class, object not null, data members are.
for me solution changing read/write method read/write every object memeber in same order.
regards
Comments
Post a Comment