Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Kevin Haube
12,265 PointsParcelabale Object recieved with null values?
So within a profile activity, when a user clicks on a post, it takes them to the PostActivity, where they can view comments, and comment themselves. Between ProfileActivity and PostActivity, I add a parcelable extra to the intent:
Intent postPage = new Intent(this, PostActivity.class);
postPage.putExtra("POST", post);
startActivity(postPage);
And I retrieve it in the new activity as such:
mIntent = getIntent();
mPost = mIntent.getParcelableExtra("POST");
Upon running the app in debug mode, I can see that it's being shipped with all the attributes set, but upon getting it in the PostActivity, it still exists as an object, but none of its values exist. They're all null.
Here is my Post object class:
package com.kevinhaube.crumbs.utils;
import android.os.Parcel;
import android.os.Parcelable;
import com.parse.ParseClassName;
import com.parse.ParseObject;
/**
* Created by kevinhaube on 4/20/15.
*/
@ParseClassName("Post")
public class Post extends ParseObject implements Parcelable {
String mAuthor;
String mLocation;
String mPostText;
int mTimeRemaining;
public Post() {
}
public String getPostText() {
return getString("postText");
}
public void setPostText(String postText) {
mPostText = postText;
put("postText", postText);
}
public String getAuthor() {
return getString("author");
}
public void setAuthor(String author) {
mAuthor = author;
put("author", author);
}
public String getLocation() {
return getString("location");
}
public void setLocation(String location) {
mLocation = location;
put("location", location);
}
public int getTimeRemaining() {
return getInt("timeRemaining");
}
public void setTimeRemaining(int time) {
mTimeRemaining = time;
put("timeRemaining", time);
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(mAuthor);
dest.writeString(mLocation);
dest.writeString(mPostText);
dest.writeInt(mTimeRemaining);
}
public static final Parcelable.Creator<Post> CREATOR = new Parcelable.Creator<Post>() {
public Post createFromParcel(Parcel in) {
return new Post(in);
}
public Post[] newArray(int size) {
return new Post[size];
}
};
private Post(Parcel in) {
mAuthor = in.readString();
mLocation = in.readString();
mPostText = in.readString();
mTimeRemaining = in.readInt();
}
}
Daniel Hartin
18,106 PointsDaniel Hartin
18,106 PointsHi Kevin
Don't know if it's applicable to your particular situation (I haven't much experience with Parcelable classes) however from what i read up on I found that implementing serializable is much easier although it's is not as efficient. In my app, I didn't notice any lag however if you are doing a number of intensive tasks it may not be the best approach.
Below is a link to an article making comparisons between the two
http://www.developerphil.com/parcelable-vs-serializable/