IdleSun's Weblog

July 29, 2011

Android Parcelable Example 3 – Subclass, Inheritance

Filed under: Android,Java — idlesun @ 7:04 am
Tags: , , , , ,

 

This post has been moved to my new blog.

 

Advertisements

5 Comments »

  1. What is the describeContents() method for anyway?

    Comment by Fred Eisele — August 9, 2011 @ 6:43 pm | Reply

  2. Hello idlesun, thank you for this tutorial, is very helpful!

    I think you forgot something though, in the sub classes one must create the CREATOR (http://developer.android.com/reference/android/os/Parcelable.Creator.html) field so that the parcel can be created.

    Ex: for RoundedRectangle you must have:

    // Static field implementing the Parcelable.Creator interface.
    public static final Creator CREATOR = new Creator() {
    public RoundedRectangle createFromParcel(Parcel in) {
    return new RoundedRectangle(in);
    }

    public RoundedRectangle[] newArray(int size) {
    return new RoundedRectangle[size];
    }
    };

    Thank you again for your post!

    Comment by Catalin — November 9, 2011 @ 12:54 pm | Reply

    • Hi Catalin, Thanks for your comments. You are absolutely right. (And my examples are so too ^ ^) I just omitted CREATOR parts in all my Parcelable examples for simplicity because they are all the same code. Instead, I added a line of comment saying “CREATOR part is omitted”. My plan was to post the full working app project source that uses these examples, but I couldn’t have time so far.

      Comment by idlesun — November 10, 2011 @ 12:55 am | Reply

  3. Thanks. This is a simple thing that I couldn’t think of it before. You saved me hours.

    Comment by Rach Mieu — November 9, 2012 @ 4:21 am | Reply

  4. thanks for share!

    Comment by manolo hangisi — October 21, 2014 @ 10:41 am | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: