Example usage for android.os Parcel recycle

List of usage examples for android.os Parcel recycle

Introduction

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

Prototype

public final void recycle() 

Source Link

Document

Put a Parcel object back into the pool.

Usage

From source file:com.harlie.android.sunshine.app.ItemChoiceManager.java

public void onRestoreInstanceState(Bundle savedInstanceState) {
    byte[] states = savedInstanceState.getByteArray(SELECTED_ITEMS_KEY);
    if (null != states) {
        Parcel inParcel = Parcel.obtain();
        inParcel.unmarshall(states, 0, states.length);
        inParcel.setDataPosition(0);/*from ww  w. j  av  a2 s .  c o m*/
        mCheckStates = inParcel.readSparseBooleanArray();
        final int numStates = inParcel.readInt();
        mCheckedIdStates.clear();
        for (int i = 0; i < numStates; i++) {
            final long key = inParcel.readLong();
            final int value = inParcel.readInt();
            mCheckedIdStates.put(key, value);
        }
        inParcel.recycle();
    }
}

From source file:org.droid2droid.internal.AbstractRemoteAndroidImpl.java

protected final void updateData(Parcel data) // TODO: a placer plutot cot serveur
{
    if (UPDATE_PARCEL) {
        int v = VERSION.SDK_INT;
        data.setDataPosition(0);/*from w ww.  j  a  va 2 s  .c  om*/
        if (v >= 10) // Gingerbread_MR1+
        {
            data.readInt();
        }
        String enforceInterfaceName = data.readString(); // Read the interface name (see Parcel.cpp)
        assert (enforceInterfaceName != null);
        byte[] bufDatas = data.marshall(); // Return all the buffer (with the specific enforceInterface
        int startDatas = data.dataPosition(); // Position after the first string

        // Create a new one with interface name + buffers
        Parcel p = Parcel.obtain();
        p.setDataPosition(0);
        p.writeString(enforceInterfaceName);
        int sizeInterface = p.dataPosition();
        byte[] bufInterface = p.marshall(); // Part of buffer only for the string
        p.recycle();

        // Extract the rest of the buffer
        byte[] result = new byte[sizeInterface + bufDatas.length - startDatas];
        System.arraycopy(bufInterface, 0, result, 0, sizeInterface);
        System.arraycopy(bufDatas, startDatas, result, sizeInterface, bufDatas.length - startDatas);
        data.unmarshall(result, 0, result.length);
    }
}

From source file:org.droid2droid.internal.AbstractRemoteAndroidImpl.java

@Override
public boolean pingBinder(int connid, int oid, long timeout) throws RemoteException {
    if (D)//from  w w w.  j  a v a  2  s  . com
        Log.d(TAG_CLIENT_BIND, PREFIX_LOG + "pingBinder...");
    if (!isBinderAlive())
        return false;
    Parcel data = Parcel.obtain();
    Parcel reply = Parcel.obtain();
    try {
        data.writeInt(oid);
        transactRemoteAndroid(getConnectionId(), PING_BINDER, data, reply, 0, timeout);
        return reply.readByte() == 1;
    } finally {
        if (data != null)
            data.recycle();
        if (reply != null)
            reply.recycle();
    }
}

From source file:org.droid2droid.internal.AbstractRemoteAndroidImpl.java

@Override
public boolean isBinderAlive(int connid, int oid, long timeout) throws RemoteException {
    if (D)/*from  w w  w  .ja v a2  s .c  om*/
        Log.d(TAG_CLIENT_BIND, PREFIX_LOG + "isBinderAlive...");
    if (!isBinderAlive()) {
        if (E)
            Log.e(TAG_CLIENT_BIND, PREFIX_LOG + "Binder is not alive");
        throw new RemoteException();
    }
    Parcel data = Parcel.obtain();
    Parcel reply = Parcel.obtain();
    try {
        data.writeInt(oid);
        transactRemoteAndroid(getConnectionId(), IS_BINDER_ALIVE, data, reply, 0, timeout);
        return reply.readByte() == 1;
    } finally {
        if (data != null)
            data.recycle();
        if (reply != null)
            reply.recycle();
    }
}

From source file:org.droid2droid.internal.AbstractRemoteAndroidImpl.java

@Override
public void finalizeOID(int connid, int oid, long timeout) {
    if (oid == 0) {
        if (E)//from   w  w  w .ja  va2s  .  co m
            Log.e(TAG_CLIENT_BIND, PREFIX_LOG + "FinalizeOID with oid=0!");
        return;
    }
    if (!isBinderAlive())
        return;
    Parcel data = Parcel.obtain();
    Parcel reply = Parcel.obtain();
    try {
        data.writeInt(oid);
        transactRemoteAndroid(getConnectionId(), FINALIZE_OID, data, reply, 0, timeout);
        return;
    } catch (RemoteException e) {
        if (V)
            Log.v(TAG_CLIENT_BIND, PREFIX_LOG + "FinalizeOID", e);
    } finally {
        if (data != null)
            data.recycle();
        if (reply != null)
            reply.recycle();
    }

}

From source file:ca.farrelltonsolar.classic.PVOutputUploader.java

private Bundle deserializeBundle(byte[] data) {
    Bundle bundle = null;/*from   w w w.j a va2 s.co  m*/
    final Parcel parcel = Parcel.obtain();
    try {
        final ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
        final byte[] buffer = new byte[1024];
        final GZIPInputStream zis = new GZIPInputStream(new ByteArrayInputStream(data));
        int len = 0;
        while ((len = zis.read(buffer)) != -1) {
            byteBuffer.write(buffer, 0, len);
        }
        zis.close();
        parcel.unmarshall(byteBuffer.toByteArray(), 0, byteBuffer.size());
        parcel.setDataPosition(0);
        bundle = parcel.readBundle();
    } catch (IOException ex) {
        Log.w(getClass().getName(), String.format("deserializeBundle failed ex: %s", ex));
        bundle = null;
    } finally {
        parcel.recycle();
    }
    return bundle;
}

From source file:com.google.android.gms.internal.fv.java

public static fv m1980e(byte[] bArr) {
    Parcel obtain = Parcel.obtain();
    obtain.unmarshall(bArr, 0, bArr.length);
    obtain.setDataPosition(0);//from www  .j av a 2 s .c  om
    fv D = CREATOR.m622D(obtain);
    obtain.recycle();
    return D;
}

From source file:org.droid2droid.internal.AbstractRemoteAndroidImpl.java

/** Send transactions to remote cloud. */
@Override/*ww w. j  ava2  s .com*/
public int bindOID(int connid, int serviceConnectionOID, Intent intent, int flags, ComponentName[] name,
        long timeout) throws RemoteException {
    if (D)
        Log.d(TAG_CLIENT_BIND, PREFIX_LOG + "BindOID...");
    Parcel data = Parcel.obtain();
    Parcel reply = Parcel.obtain();
    try {

        data.writeInt(serviceConnectionOID);
        NormalizeIntent.writeIntent(intent, data, 0);
        data.writeInt(flags);
        transactRemoteAndroid(connid, BIND_OID, data, reply, 0, timeout);
        if (D)
            Log.d(TAG_CLIENT_BIND, PREFIX_LOG + "BindOID ok");
        name[0] = (ComponentName) reply.readParcelable(ComponentName.class.getClassLoader());
        return reply.readInt();
    } finally {
        if (data != null)
            data.recycle();
        if (reply != null)
            reply.recycle();
    }
}

From source file:org.droid2droid.internal.AbstractRemoteAndroidImpl.java

@Override
public boolean unbindService(ServiceConnection conn) {
    synchronized (mBinders) {
        Binded binder = mBinders.get(conn);
        if (binder != null) {
            if (D)
                Log.d(TAG_CLIENT_BIND, PREFIX_LOG + "UnBindOID...");
            Parcel data = Parcel.obtain();
            Parcel reply = Parcel.obtain();
            try {

                try {
                    data.writeInt(System.identityHashCode(conn));
                    transactRemoteAndroid(getConnectionId(), UNBIND_SRV, data, reply, 0, mExecuteTimeout);
                    if (D)
                        Log.d(TAG_CLIENT_BIND, PREFIX_LOG + "UnBindOID ok");
                } catch (RemoteException e) {
                    if (W && !D)
                        Log.w(TAG_CLIENT_BIND, "Error when unbind (" + e.getMessage() + ")");
                    if (D)
                        Log.w(TAG_CLIENT_BIND, "Errer when unbind", e);
                }//from   w  ww  .ja  va 2s . co  m
            } finally {
                if (data != null)
                    data.recycle();
                if (reply != null)
                    reply.recycle();
            }
            mBinders.remove(conn);
        } else
            return false;
    }

    return true;
}