Just call intent.getParcelable() again.

--
Kostya Vasilyev -- http://kmansoft.wordpress.com

16.09.2010 22:55 пользователь "Mark Wyszomierski" <[email protected]>
написал:

Hi,

I've implemented parcelable on a class of mine per the doc
instructions, works fine:

   public class MyParcelable implements Parcelable {
       ...
       public static final Parcelable.Creator<MyParcelable> CREATOR
            = new Parcelable.Creator<MyParcelable>() {
           public MyParcelable createFromParcel(Parcel in) {
              return new MyParcelable(in);
           }

           ...
       };
   }

I'm interested in the createFromParcel() method. I pass an instance of
MyParcelable to a new activity like this:

   Intent intent = new Intent(...);
   intent.putExtra("key", myParcelableInstance);
   startActivity(intent);

and pick it up from the new activity like this:

   MyParcelable mp =
(MyParcelable)getIntent().getExtras().getParcelable("key");

I'd like to make a copy of the MyParcelable instance, like so:

   MyParcelable mp2 = new MyParcelable(mp);

but I haven't implemented a copy constructor. However, the
createFromParcel() method which I did implement is almost like a copy
constructor. I'm wondering if I can use it make a copy, but I can't
figure out how to get a Parcel instance from the intent extras:

   MyParcelable mp2 =
       MyParcelable.CREATOR.createFromParcel(
           getIntent().getExtras().getParcelable("key"));  // ? just
need a parcel ?

it's not the greatest idea, just wondering if it's possible to avoid
making another method for my class which will almost be identical to
what's already implemented for the Parcelable interface,

Thanks

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]<android-developers%[email protected]>
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to