write To Parcel - Android android.os

Android examples for android.os:Parcel

Description

write To Parcel

Demo Code


//package com.java2s;
import android.os.Parcel;
import android.os.Parcelable;

public class Main {
    final static int EXIST_SEPARATOR = 1;
    final static int NON_SEPARATOR = 0;

    public static void writeToParcel(Parcel out, String str) {
        if (str != null) {
            out.writeInt(EXIST_SEPARATOR);
            out.writeString(str);/*from www . java 2  s.  co m*/
        } else {
            out.writeInt(NON_SEPARATOR);
        }
    }

    public static <T extends Parcelable> void writeToParcel(Parcel out,
            T model) {
        if (model != null) {
            out.writeInt(EXIST_SEPARATOR);
            out.writeParcelable(model, 0);
        } else {
            out.writeInt(NON_SEPARATOR);
        }
    }
}

Related Tutorials