本文整理汇总了Java中android.os.Parcel.marshall方法的典型用法代码示例。如果您正苦于以下问题:Java Parcel.marshall方法的具体用法?Java Parcel.marshall怎么用?Java Parcel.marshall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.Parcel
的用法示例。
在下文中一共展示了Parcel.marshall方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testParcelling
import android.os.Parcel; //导入方法依赖的package包/类
@Test
public void testParcelling() {
PersistableBundle bundle = new PersistableBundle();
bundle.putString("string", "string");
bundle.putInt("int", 0);
bundle.putLong("long", 0);
bundle.putBoolean("boolean", true);
// Can't use double or any array, as the instances would be different and equals() would fail.
Parcel parcel = Parcel.obtain();
parcel.writeValue(bundle);
byte[] bytes = parcel.marshall();
parcel.recycle();
parcel = Parcel.obtain();
parcel.unmarshall(bytes, 0, bytes.length);
parcel.setDataPosition(0);
PersistableBundle parcelledBundle =
(PersistableBundle) parcel.readValue(PersistableBundle.class.getClassLoader());
assertEquals(bundle.toMap(1), parcelledBundle.toMap(1));
}
示例2: parcelClone
import android.os.Parcel; //导入方法依赖的package包/类
public MasterSecret parcelClone() {
Parcel thisParcel = Parcel.obtain();
Parcel thatParcel = Parcel.obtain();
byte[] bytes = null;
thisParcel.writeValue(this);
bytes = thisParcel.marshall();
thatParcel.unmarshall(bytes, 0, bytes.length);
thatParcel.setDataPosition(0);
MasterSecret that = (MasterSecret)thatParcel.readValue(MasterSecret.class.getClassLoader());
thisParcel.recycle();
thatParcel.recycle();
return that;
}
示例3: createResponseMap
import android.os.Parcel; //导入方法依赖的package包/类
@NonNull
private Map<String, Object> createResponseMap(Parcel reply) {
Map<String, Object> data = new HashMap<>();
data.put("message", "reply");
if (reply != null) {
try {
byte[] marshalled = reply.marshall();
data.put("data", marshalled);
if (marshalled != null) {
String base64 = BaseEncoding.base64().encode(marshalled).replace("/", "");
data.put("data_base64", base64);
}
} catch (RuntimeException e) {
data.put("info", "activeObject");
}
}
return data;
}
示例4: save
import android.os.Parcel; //导入方法依赖的package包/类
/**
* Saves the repeatable intent (useful for later cancelling an alarm after the application has restarted)
*
* @param siteToSiteRepeatableIntent the repeatable intent
*/
public void save(SiteToSiteRepeatableIntent siteToSiteRepeatableIntent) {
Parcel parcel = Parcel.obtain();
siteToSiteRepeatableIntent.getIntent().writeToParcel(parcel, 0);
parcel.setDataPosition(0);
byte[] bytes = parcel.marshall();
SQLiteDatabase writableDatabase = sqLiteOpenHelper.getWritableDatabase();
try {
ContentValues contentValues = new ContentValues();
contentValues.put(PENDING_INTENT_REQUEST_CODE, siteToSiteRepeatableIntent.getRequestCode());
contentValues.put(CONTENT_COLUMN, bytes);
writableDatabase.insertOrThrow(PENDING_INTENT_TABLE_NAME, null, contentValues);
} finally {
writableDatabase.close();
}
}
示例5: marshall
import android.os.Parcel; //导入方法依赖的package包/类
public static byte[] marshall(Parcelable parceable) {
Parcel parcel = Parcel.obtain();
parceable.writeToParcel(parcel, 0);
byte[] bytes = parcel.marshall();
parcel.recycle();
return bytes;
}
示例6: parcelable2Bytes
import android.os.Parcel; //导入方法依赖的package包/类
private static byte[] parcelable2Bytes(final Parcelable parcelable) {
if (parcelable == null) return null;
Parcel parcel = Parcel.obtain();
parcelable.writeToParcel(parcel, 0);
byte[] bytes = parcel.marshall();
parcel.recycle();
return bytes;
}
示例7: serialize
import android.os.Parcel; //导入方法依赖的package包/类
public static byte[] serialize(Parcelable parceable) {
Parcel parcel = Parcel.obtain();
parceable.writeToParcel(parcel, 0);
byte[] bytes = parcel.marshall();
parcel.recycle();
return bytes;
}
示例8: marshall
import android.os.Parcel; //导入方法依赖的package包/类
static byte[] marshall(Object o) {
Parcel parcel = Parcel.obtain();
parcel.writeValue(o);
byte[] result = parcel.marshall();
parcel.recycle();
return result;
}
示例9: parcelableToByteArray
import android.os.Parcel; //导入方法依赖的package包/类
private <T extends Parcelable> byte[] parcelableToByteArray(T parcelable) {
Parcel parcel = Parcel.obtain();
parcel.writeParcelable(parcelable, 0);
byte[] data = parcel.marshall();
parcel.recycle();
return data;
}
示例10: clone
import android.os.Parcel; //导入方法依赖的package包/类
public RecordFood clone() {
Parcel parcel = Parcel.obtain();
writeToParcel(parcel, 0);
byte[] bytes = parcel.marshall();
Parcel parcel2 = Parcel.obtain();
parcel2.unmarshall(bytes, 0, bytes.length);
parcel2.setDataPosition(0);
return (RecordFood) CREATOR.createFromParcel(parcel2);
}
示例11: marshallRequest
import android.os.Parcel; //导入方法依赖的package包/类
private byte[] marshallRequest(int token, byte data[]) {
Parcel p = Parcel.obtain();
p.writeInt(RIL_REQUEST_OEM_RAW);
p.writeInt(token);
p.writeByteArray(data);
byte[] res = p.marshall();
p.recycle();
return res;
}
示例12: parcelable2Bytes
import android.os.Parcel; //导入方法依赖的package包/类
private static byte[] parcelable2Bytes(Parcelable parcelable) {
if (parcelable == null) return null;
Parcel parcel = Parcel.obtain();
parcelable.writeToParcel(parcel, 0);
byte[] bytes = parcel.marshall();
parcel.recycle();
return bytes;
}
示例13: marshallParcelable
import android.os.Parcel; //导入方法依赖的package包/类
/**
* Marshalls a parcelable into a byte array
*
* @param parcelable the parcelable
* @param <T> the type
* @return the byte array
*/
public static <T extends Parcelable> byte[] marshallParcelable(T parcelable) {
if (parcelable == null) {
return null;
}
Parcel parcel = Parcel.obtain();
parcelable.writeToParcel(parcel, 0);
parcel.setDataPosition(0);
try {
return parcel.marshall();
} finally {
parcel.recycle();
}
}
示例14: marshallSerializable
import android.os.Parcel; //导入方法依赖的package包/类
/**
* Marshalls a serializable into a byte array
*
* @param serializable the serializable
* @param <T> the type
* @return the byte array
*/
public static <T extends Serializable> byte[] marshallSerializable(T serializable) {
if (serializable == null) {
return null;
}
Parcel parcel = Parcel.obtain();
parcel.writeSerializable(serializable);
parcel.setDataPosition(0);
try {
return parcel.marshall();
} finally {
parcel.recycle();
}
}
示例15: onSaveInstanceState
import android.os.Parcel; //导入方法依赖的package包/类
public void onSaveInstanceState(Bundle outState) {
Parcel outParcel = Parcel.obtain();
outParcel.writeSparseBooleanArray(mCheckStates);
final int numStates = mCheckedIdStates.size();
outParcel.writeInt(numStates);
for (int i=0; i<numStates; i++) {
outParcel.writeLong(mCheckedIdStates.keyAt(i));
outParcel.writeInt(mCheckedIdStates.valueAt(i));
}
byte[] states = outParcel.marshall();
outState.putByteArray(SELECTED_ITEMS_KEY, states);
outParcel.recycle();
}