Example usage for android.os Parcel writeParcelable

List of usage examples for android.os Parcel writeParcelable

Introduction

In this page you can find the example usage for android.os Parcel writeParcelable.

Prototype

public final void writeParcelable(Parcelable p, int parcelableFlags) 

Source Link

Document

Flatten the name of the class of the Parcelable and its contents into the parcel.

Usage

From source file:Main.java

public static boolean writeParcelable(Context context, String fileName, Parcelable parcelObject) {
    boolean success = false;
    FileOutputStream fos = null;/*  w w w  .  j  a va 2  s.  c  om*/
    try {
        fos = context.openFileOutput(fileName, Context.MODE_PRIVATE);
        Parcel parcel = Parcel.obtain();
        parcel.writeParcelable(parcelObject, Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
        byte[] data = parcel.marshall();
        fos.write(data);

        success = true;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (fos != null) {
            try {
                fos.close();
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
        }
    }

    return success;
}

From source file:Main.java

/**
 * Write a HashMap to a Parcel, class of key and value can parcelable both
 * /*from w w  w . j  a  v  a2s . c  om*/
 * @param map
 * @param out
 * @param flags
 */
public static <K extends Parcelable, V extends Parcelable> void writeHashMap(Map<K, V> map, Parcel out,
        int flags) {
    if (map != null) {
        out.writeInt(map.size());

        for (Entry<K, V> entry : map.entrySet()) {
            out.writeParcelable(entry.getKey(), flags);
            out.writeParcelable(entry.getValue(), flags);
        }
    } else {
        out.writeInt(-1);
    }
}

From source file:com.facebook.TestUtils.java

public static <E extends Parcelable> E parcelAndUnparcel(final E object) {
    final Parcel writeParcel = Parcel.obtain();
    final Parcel readParcel = Parcel.obtain();
    try {/*w  w w . j  a  v a 2s. c  o  m*/
        writeParcel.writeParcelable(object, 0);
        final byte[] bytes = writeParcel.marshall();
        readParcel.unmarshall(bytes, 0, bytes.length);
        readParcel.setDataPosition(0);
        return readParcel.readParcelable(object.getClass().getClassLoader());
    } finally {
        writeParcel.recycle();
        readParcel.recycle();
    }
}

From source file:com.baasbox.android.BaasLink.java

private static void writeObject(Parcel p, BaasObject o) {
    if (o == null) {
        p.writeByte((byte) 0);
    } else {/*from   ww w .  ja v a 2 s  . c  o  m*/
        if (o instanceof BaasDocument) {
            p.writeByte((byte) 1);
        } else if (o instanceof BaasFile) {
            p.writeByte((byte) 2);
        }
        p.writeParcelable(o, 0);
    }
}

From source file:com.tigerpenguin.places.model.Period.java

@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeParcelable(openingTime, flags);
    dest.writeParcelable(closingTime, flags);
}

From source file:org.dmfs.android.microfragments.utils.BooleanCage.java

public void writeToParcel(Parcel dest, int flags) {
    dest.writeParcelable(this.mIntent, flags);
}

From source file:org.dmfs.pigeonpost.localbroadcast.ParcelableCage.java

@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeParcelable(mIntent, flags);
}

From source file:com.richtodd.android.quiltdesign.block.QuiltBlock.java

@Override
public void writeToParcel(Parcel out, int flags) {
    out.writeParcelable(m_block, 0);
}

From source file:org.dmfs.android.microfragments.transitions.BottomUp.java

@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeParcelable(mDelegate, flags);
}

From source file:com.tigerpenguin.places.model.Geometry.java

@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeParcelable(location, flags);
    // Android documentation recommends using writeBundle() instead of writeMap()
    Bundle bundle = null;/*  w  w w  . j  av a 2 s. c  o  m*/
    if (viewports != null && viewports.size() > 0) {
        bundle = new Bundle();
        for (Map.Entry<String, PlaceLocation> viewport : viewports.entrySet()) {
            bundle.putParcelable(viewport.getKey(), viewport.getValue());
        }
    }
    dest.writeBundle(bundle);
}