write Type List to Parcel - Android android.os

Android examples for android.os:Parcel

Description

write Type List to Parcel

Demo Code


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

import java.util.List;

public class Main {
    public static <T extends Parcelable> void writeTypeList(Parcel dest,
            List<T> list) {
        boolean isNull = list == null;
        writeBoolean(dest, isNull);//from ww w. j  av  a  2s.c  o m
        if (!isNull) {
            dest.writeTypedList(list);
        }
    }

    public static void writeBoolean(Parcel dest, boolean value) {
        dest.writeInt(toInt(value));
    }

    public static int toInt(boolean value) {
        return value ? 1 : 0;
    }
}

Related Tutorials