本文整理了Java中android.os.Bundle.writeToParcel()
方法的一些代码示例,展示了Bundle.writeToParcel()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bundle.writeToParcel()
方法的具体详情如下:
包路径:android.os.Bundle
类名称:Bundle
方法名:writeToParcel
暂无
代码示例来源:origin: firebase/firebase-jobdispatcher-android
private static Parcel toParcel(Bundle data) {
Parcel serialized = Parcel.obtain();
data.writeToParcel(serialized, 0);
serialized.setDataPosition(0);
return serialized;
}
代码示例来源:origin: firebase/firebase-jobdispatcher-android
/** @see #MAX_EXTRAS_SIZE_BYTES */
private static int measureBundleSize(Bundle extras) {
Parcel p = Parcel.obtain();
extras.writeToParcel(p, 0);
int sizeInBytes = p.dataSize();
p.recycle();
return sizeInBytes;
}
代码示例来源:origin: LawnchairLauncher/Lawnchair
@Override
public void windowAttached2(Bundle bundle, ILauncherOverlayCallback iLauncherOverlayCallback) throws RemoteException {
IBinder iBinder = null;
Parcel obtain = Parcel.obtain();
try {
obtain.writeInterfaceToken("com.google.android.libraries.launcherclient.ILauncherOverlay");
if (bundle == null) {
obtain.writeInt(0);
} else {
obtain.writeInt(1);
bundle.writeToParcel(obtain, 0);
}
if (iLauncherOverlayCallback != null) {
iBinder = iLauncherOverlayCallback.asBinder();
}
obtain.writeStrongBinder(iBinder);
this.mRemote.transact(14, obtain, null, FLAG_ONEWAY);
} finally {
obtain.recycle();
}
}
代码示例来源:origin: stackoverflow.com
//Create parcelable object and put to Bundle
Question q = new Question(questionId, surveyServerId, title, type, answers);
Bundle b = new Bundle();
b.putParcelable("someTag", q);
//Save bundle to parcel
Parcel parcel = Parcel.obtain();
b.writeToParcel(parcel, 0);
//Extract bundle from parcel
parcel.setDataPosition(0);
Bundle b2 = parcel.readBundle();
b2.setClassLoader(Question.class.getClassLoader());
Question q2 = b2.getParcelable("someTag");
//Check that objects are not same and test that objects are equal
assertFalse("Bundle is the same", b2 == b);
assertFalse("Question is the same", q2 == q);
assertTrue("Questions aren't equal", q2.equals(q));
代码示例来源:origin: stackoverflow.com
Bundle in = ...;
OutputStream os = ...
Parcel p = Parcel.obtain(); //create empty parcel object
in.writeToParcel(p, 0); //saving bundle as parcel
os.write(p.marshall()); //write parcel to stream
代码示例来源:origin: stackoverflow.com
Bundle in=yourBundle;
FileOutputStream fos = context.openFileOutput(localFilename, Context.MODE_PRIVATE);
Parcel p = Parcel.obtain(); //creating empty parcel object
in.writeToParcel(p, 0); //saving bundle as parcel
fos.write(p.marshall()); //writing parcel to file
fos.flush();
fos.close();
代码示例来源:origin: OceanLabs/Android-Print-SDK
/*****************************************************
*
* Returns a parcel containing the contents of a bundle.
*
*****************************************************/
static public Parcel parcelFromBundle( Bundle bundle )
{
Parcel parcel = Parcel.obtain();
bundle.writeToParcel( parcel, 0 );
return ( parcel );
}
代码示例来源:origin: stackoverflow.com
private void put(SQLiteDatabase db, String name, Bundle bundle) {
ByteArrayOutputStream valueStream = new ByteArrayOutputStream();
try {
ContentValues rows = new ContentValues();
rows.put("name", name);
Parcel p = Parcel.obtain();
bundle.writeToParcel(p, 0);
valueStream.write(p.marshall());
rows.put("value", valueStream.toByteArray());
db.insert("bundles", null, rows);
valueStream.close();
} catch (IOException e) {
Log.e("error writing object", e.toString());
}
}
代码示例来源:origin: Doist/JobSchedulerCompat
private static Parcel toParcel(Bundle data) {
Parcel serialized = Parcel.obtain();
data.writeToParcel(serialized, 0);
serialized.setDataPosition(0);
return serialized;
}
代码示例来源:origin: stackoverflow.com
Bundle bundle = shortcutIntent.getExtras();
Parcel parcel = Parcel.obtain();
bundle.writeToParcel(parcel, 0);
byte[] byt = parcel.marshall();
String s = Base64.encodeToString(byt, 0, byt.length, 0); //store this string to sqlite
byte[] newByt = Base64.decode(s, 0);
Bundle newBundle = new Bundle();
Parcel newParcel = Parcel.obtain();
newParcel.unmarshall(newByt, 0, newByt.length);
newParcel.setDataPosition(0);
newBundle.readFromParcel(newParcel);
Intent intent = new Intent();
intent.putExtras(newBundle);
MainActivity.getContext().startActivity((Intent)intent.getExtras().get(Intent.EXTRA_SHORTCUT_INTENT));
代码示例来源:origin: powerpoint45/Lucid-Browser
public void saveToPreferences(Bundle in) {
Parcel parcel = Parcel.obtain();
String serialized = null;
try {
in.writeToParcel(parcel, 0);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
//IOUtils.write(parcel.marshall(), bos);
bos.write(parcel.marshall(),0,parcel.marshall().length);
serialized = Base64.encodeToString(bos.toByteArray(), 0);
} catch (Exception e) {
Log.e(getClass().getSimpleName(), e.toString(), e);
} finally {
parcel.recycle();
}
if (serialized != null) {
SharedPreferences settings = activity.getSharedPreferences("instance", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("parcel", serialized);
editor.commit();
}
}
代码示例来源:origin: org.infobip.mobile.messaging.api/infobip-mobile-messaging-android-sdk
private String serialize(Bundle in) {
Parcel parcel = Parcel.obtain();
try {
in.writeToParcel(parcel, 0);
return Base64.encodeToString(parcel.marshall(), 0);
} finally {
parcel.recycle();
}
}
代码示例来源:origin: limpoxe/Android-ServiceManager
@Override
public final boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException {
switch (code) {
case INTERFACE_TRANSACTION: {
reply.writeString(DESCRIPTOR);
return true;
}
case FIRST_CODE: {
data.enforceInterface(DESCRIPTOR);
Bundle param;
if ((0 != data.readInt())) {
param = Bundle.CREATOR.createFromParcel(data);
} else {
param = null;
}
Bundle result = MethodRouter.routerToInstance(param);
reply.writeNoException();
if ((result != null)) {
reply.writeInt(1);
result.writeToParcel(reply, android.os.Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
} else {
reply.writeInt(0);
}
return true;
}
}
return super.onTransact(code, data, reply, flags);
}
代码示例来源:origin: derry/delion
private Bundle createDeepCopy(Bundle original) {
Parcel temp = Parcel.obtain();
original.writeToParcel(temp, 0);
temp.setDataPosition(0);
Bundle copy = temp.readBundle();
temp.recycle();
return copy;
}
}
代码示例来源:origin: auth0/JWTDecode.Android
@Test
public void shouldBeParceled() throws Exception {
JWT jwtOrigin = new JWT("eyJhbGciOiJIUzI1NiJ9.e30.K17vlwhE8FCMShdl1_65jEYqsQqBOVMPUU9IgG-QlTM");
assertThat(jwtOrigin, is(notNullValue()));
Bundle bundleOrigin = new Bundle();
bundleOrigin.putParcelable("jwt", jwtOrigin);
Parcel parcel = Parcel.obtain();
bundleOrigin.writeToParcel(parcel, 0);
//Extract bundle from parcel
parcel.setDataPosition(0);
Bundle bundleDest = parcel.readBundle(JWT.class.getClassLoader());
JWT jwtDest = bundleDest.getParcelable("jwt");
assertThat(jwtDest, is(notNullValue()));
assertThat(bundleOrigin, is(not(bundleDest)));
assertThat(jwtOrigin, is(not(jwtDest)));
assertThat(jwtOrigin.toString(), is(jwtDest.toString()));
}
代码示例来源:origin: limpoxe/Android-ServiceManager
private static Bundle transact(String descriptor, IBinder remote, Bundle param) throws RemoteException {
android.os.Parcel _data = android.os.Parcel.obtain();
android.os.Parcel _reply = android.os.Parcel.obtain();
Bundle _result;
try {
_data.writeInterfaceToken(descriptor);
if ((param != null)) {
_data.writeInt(1);
param.writeToParcel(_data, 0);
} else {
_data.writeInt(0);
}
remote.transact(ProcessBinder.FIRST_CODE, _data, _reply, 0);
_reply.readException();
if ((0 != _reply.readInt())) {
_result = Bundle.CREATOR.createFromParcel(_reply);
} else {
_result = null;
}
} finally {
_reply.recycle();
_data.recycle();
}
return _result;
}
}
代码示例来源:origin: shyluo/CrashImmuneDecoder
public boolean config(Bundle params) throws RemoteException {
Parcel data = Parcel.obtain();
Parcel reply = Parcel.obtain();
int result = 0;
try {
data.writeInterfaceToken(DESCRIPTION);
params.writeToParcel(data, 0);
remote.transact(CONFIG_TRANSACTION, data, reply, 0);
reply.readException();
result = reply.readInt();
} finally {
reply.recycle();
data.recycle();
}
return result != 0;
}
代码示例来源:origin: baasbox/Android-SDK
public void testCanParcelJson(){
JsonObject o = new JsonObject();
o.put("Key1", "val1");
o.put("Key2", new JsonObject().put("a", "a").put("b", new JsonArray().add(new JsonObject().put("x", "x"))));
Bundle b = new Bundle();
b.putParcelable("SAVE",o);
Parcel p = Parcel.obtain();
b.writeToParcel(p,0);
p.setDataPosition(0);
Bundle readBack = p.readBundle();
readBack.setClassLoader(BaasDocument.class.getClassLoader());
JsonObject backObj = readBack.getParcelable("SAVE");
assertEquals(o.toString(),backObj.toString());
}
代码示例来源:origin: baasbox/Android-SDK
public void testCanParcelDocuments(){
BaasDocument doc = new BaasDocument("fake");
doc.put("Key", "Val1");
doc.put("Key2", "Val2");
doc.put("Key3", new JsonArray().add("ciao"));
Bundle b = new Bundle();
b.putParcelable("SAVE",doc);
Parcel p = Parcel.obtain();
b.writeToParcel(p,0);
p.setDataPosition(0);
Bundle readBack = p.readBundle();
readBack.setClassLoader(BaasDocument.class.getClassLoader());
BaasDocument newDoc = readBack.getParcelable("SAVE");
assertEquals(newDoc.getString("Key"),doc.getString("Key"));
assertEquals(newDoc.getString("Key2"),doc.getString("Key2"));
assertEquals(newDoc.getArray("Key3").getString(0),doc.getArray("Key3").getString(0));
}
代码示例来源:origin: baasbox/Android-SDK
b.writeToParcel(p,0);
p.setDataPosition(0);
Bundle readBack = p.readBundle();
内容来源于网络,如有侵权,请联系作者删除!