Advertisement
MarRab

Parcelable enum

Aug 17th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1.     public enum Type implements Parcelable {
  2.         first(0), second(1), third(2), fourth(3), fifth(4);
  3.  
  4.         private int type;
  5.  
  6.         Type(int type) {
  7.             this.type = type;
  8.         }
  9.  
  10.         public int type() {
  11.             return type;
  12.         }
  13.  
  14.         @Override
  15.         public int describeContents() {
  16.             return 0;
  17.         }
  18.  
  19.         @Override
  20.         public void writeToParcel(final Parcel dest, final int flags) {
  21.             dest.writeInt(ordinal());
  22.         }
  23.  
  24.         public static final Creator<Type> CREATOR = new Creator<Type>() {
  25.             @Override
  26.             public Type createFromParcel(final Parcel source) {
  27.                 return Type.values()[source.readInt()];
  28.             }
  29.  
  30.             @Override
  31.             public Type[] newArray(final int size) {
  32.                 return new Type[size];
  33.             }
  34.         };
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement