Advertisement
NelloRizzo

[GTN] Parceleable UserInfo

Jan 11th, 2018
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. package local.example.guessthenumber;
  2.  
  3. import android.os.Parcel;
  4. import android.os.Parcelable;
  5.  
  6. /**
  7.  * Created by Nello on 11/01/2018.
  8.  */
  9.  
  10. public class UserInfo implements Parcelable {
  11.     public final String userName;
  12.     public final String password;
  13.     private int version;
  14.  
  15.     public UserInfo(String userName, String password) {
  16.         this.userName = userName;
  17.         this.password = password;
  18.         this.version = 1;
  19.     }
  20.  
  21.     protected UserInfo(Parcel in) {
  22.         version = in.readInt();
  23.         if (version == 1) {
  24.             userName = in.readString();
  25.             password = in.readString();
  26.         }
  27.         else
  28.         {
  29.             userName = "Noname";
  30.             password = "";
  31.         }
  32.     }
  33.  
  34.     public static final Creator<UserInfo> CREATOR = new Creator<UserInfo>() {
  35.         @Override
  36.         public UserInfo createFromParcel(Parcel in) {
  37.             return new UserInfo(in);
  38.         }
  39.  
  40.         @Override
  41.         public UserInfo[] newArray(int size) {
  42.             return new UserInfo[size];
  43.         }
  44.     };
  45.  
  46.     @Override
  47.     public int describeContents() {
  48.         return 0;
  49.     }
  50.  
  51.     @Override
  52.     public void writeToParcel(Parcel parcel, int i) {
  53.         parcel.writeInt(version);
  54.         parcel.writeString(userName);
  55.         parcel.writeString(password);
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement