Example usage for android.os Parcelable PARCELABLE_WRITE_RETURN_VALUE

List of usage examples for android.os Parcelable PARCELABLE_WRITE_RETURN_VALUE

Introduction

In this page you can find the example usage for android.os Parcelable PARCELABLE_WRITE_RETURN_VALUE.

Prototype

int PARCELABLE_WRITE_RETURN_VALUE

To view the source code for android.os Parcelable PARCELABLE_WRITE_RETURN_VALUE.

Click Source Link

Document

Flag for use with #writeToParcel : the object being written is a return value, that is the result of a function such as "Parcelable someFunction()", "void someFunction(out Parcelable)", or "void someFunction(inout Parcelable)".

Usage

From source file:Main.java

public static boolean writeParcelable(Context context, String fileName, Parcelable parcelObject) {
    boolean success = false;
    FileOutputStream fos = null;/*from   w w  w. ja  va  2s.c  o m*/
    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;
}