Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>about Oderik's post:</p> <blockquote> <p>You can make your enum implement Parcelable which is quite easy for enums:</p> <p>public enum MyEnum implements Parcelable { ... } You can than use Intent.putExtra(String, Parcelable).</p> </blockquote> <p>If you define a MyEnum variable myEnum, then do intent.putExtra("Parcelable1", myEnum), you will get a "The method putExtra(String, Parcelable) is ambiguous for the type Intent" error message. because there is also a Intent.putExtra(String, Parcelable) method, and original 'Enum' type itself implements the Serializable interface, so compiler does not know choose which method(intent.putExtra(String, Parcelable/or Serializable)).</p> <p>Suggest that remove the Parcelable interface from MyEnum, and move the core code into wrap class' Parcelable implementation, like this(Father2 is a Parcelable and contain an enum field):</p> <pre><code>public class Father2 implements Parcelable { AnotherEnum mAnotherEnum; int mField; public Father2(AnotherEnum myEnum, int field) { mAnotherEnum = myEnum; mField = field; } private Father2(Parcel in) { mField = in.readInt(); mAnotherEnum = AnotherEnum.values()[in.readInt()]; } public static final Parcelable.Creator&lt;Father2&gt; CREATOR = new Parcelable.Creator&lt;Father2&gt;() { public Father2 createFromParcel(Parcel in) { return new Father2(in); } @Override public Father2[] newArray(int size) { return new Father2[size]; } }; @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(mField); dest.writeInt(mAnotherEnum.ordinal()); } } </code></pre> <p>then we can do:</p> <pre><code>AnotherEnum anotherEnum = AnotherEnum.Z; intent.putExtra("Serializable2", AnotherEnum.X); intent.putExtra("Parcelable2", new Father2(AnotherEnum.X, 7)); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload