本文整理汇总了Java中android.os.Parcel.obtain方法的典型用法代码示例。如果您正苦于以下问题:Java Parcel.obtain方法的具体用法?Java Parcel.obtain怎么用?Java Parcel.obtain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.Parcel
的用法示例。
在下文中一共展示了Parcel.obtain方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findService
import android.os.Parcel; //导入方法依赖的package包/类
private IBinder findService(String name){
Parcel data = Parcel.obtain();
data.writeString(name);
Parcel reply = Parcel.obtain();
try {
mRemoteServiceManager.transact(ServiceContext.GET_SERVICE, data, reply, 0);
IBinder service = reply.readStrongBinder();
log("getService result binder = " + service);
return service;
} catch (RemoteException e) {
e.printStackTrace();
log("getService exception");
return null;
} finally {
data.recycle();
reply.recycle();
}
}
示例2: newSession
import android.os.Parcel; //导入方法依赖的package包/类
public boolean newSession(ICustomTabsCallback callback) throws RemoteException {
Parcel _data = Parcel.obtain();
Parcel _reply = Parcel.obtain();
boolean _result;
try {
_data.writeInterfaceToken("android.support.customtabs.ICustomTabsService");
_data.writeStrongBinder(callback != null ? callback.asBinder() : null);
this.mRemote.transact(3, _data, _reply, 0);
_reply.readException();
_result = 0 != _reply.readInt();
} finally {
_reply.recycle();
_data.recycle();
}
return _result;
}
示例3: playFromUri
import android.os.Parcel; //导入方法依赖的package包/类
public void playFromUri(Uri uri, Bundle extras) throws RemoteException {
Parcel _data = Parcel.obtain();
Parcel _reply = Parcel.obtain();
try {
_data.writeInterfaceToken(Stub.DESCRIPTOR);
if (uri != null) {
_data.writeInt(1);
uri.writeToParcel(_data, 0);
} else {
_data.writeInt(0);
}
if (extras != null) {
_data.writeInt(1);
extras.writeToParcel(_data, 0);
} else {
_data.writeInt(0);
}
this.mRemote.transact(16, _data, _reply, 0);
_reply.readException();
} finally {
_reply.recycle();
_data.recycle();
}
}
示例4: getPlaybackState
import android.os.Parcel; //导入方法依赖的package包/类
public PlaybackStateCompat getPlaybackState() throws RemoteException {
Parcel _data = Parcel.obtain();
Parcel _reply = Parcel.obtain();
try {
PlaybackStateCompat _result;
_data.writeInterfaceToken(Stub.DESCRIPTOR);
this.mRemote.transact(28, _data, _reply, 0);
_reply.readException();
if (_reply.readInt() != 0) {
_result = (PlaybackStateCompat) PlaybackStateCompat.CREATOR.createFromParcel(_reply);
} else {
_result = null;
}
_reply.recycle();
_data.recycle();
return _result;
} catch (Throwable th) {
_reply.recycle();
_data.recycle();
}
}
示例5: getDeviceInfo
import android.os.Parcel; //导入方法依赖的package包/类
public DeviceInfo getDeviceInfo(String deviceId) throws RemoteException {
Parcel _data = Parcel.obtain();
Parcel _reply = Parcel.obtain();
try {
DeviceInfo _result;
_data.writeInterfaceToken(Stub.DESCRIPTOR);
_data.writeString(deviceId);
this.mRemote.transact(3, _data, _reply, 0);
ExceptionUtils.readExceptionFromParcel(_reply);
if (_reply.readInt() != 0) {
_result = (DeviceInfo) DeviceInfo.CREATOR.createFromParcel(_reply);
} else {
_result = null;
}
_reply.recycle();
_data.recycle();
return _result;
} catch (Throwable th) {
_reply.recycle();
_data.recycle();
}
}
示例6: sendCustomAction
import android.os.Parcel; //导入方法依赖的package包/类
public void sendCustomAction(String action, Bundle args) throws RemoteException {
Parcel _data = Parcel.obtain();
Parcel _reply = Parcel.obtain();
try {
_data.writeInterfaceToken(Stub.DESCRIPTOR);
_data.writeString(action);
if (args != null) {
_data.writeInt(1);
args.writeToParcel(_data, 0);
} else {
_data.writeInt(0);
}
this.mRemote.transact(26, _data, _reply, 0);
_reply.readException();
} finally {
_reply.recycle();
_data.recycle();
}
}
示例7: warmup
import android.os.Parcel; //导入方法依赖的package包/类
public boolean warmup(long flags) throws RemoteException {
Parcel _data = Parcel.obtain();
Parcel _reply = Parcel.obtain();
boolean _result;
try {
_data.writeInterfaceToken("android.support.customtabs.ICustomTabsService");
_data.writeLong(flags);
this.mRemote.transact(2, _data, _reply, 0);
_reply.readException();
_result = 0 != _reply.readInt();
} finally {
_reply.recycle();
_data.recycle();
}
return _result;
}
示例8: testWriteAndReadParcel
import android.os.Parcel; //导入方法依赖的package包/类
@Test
public void testWriteAndReadParcel() throws Exception {
Parcel p = Parcel.obtain();
p.writeParcelable(QUERY_RESPONSE, 0);
p.setDataPosition(0);
QueryResponse read = p.readParcelable(QueryResponse.class.getClassLoader());
assertThat(read.responderPackage).isEqualTo(QUERY_RESPONSE.responderPackage);
assertThat(read.responseId).isEqualTo(QUERY_RESPONSE.responseId);
assertThat(read.responseMessage).isEqualTo(QUERY_RESPONSE.responseMessage);
}
示例9: 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;
}
示例10: save
import android.os.Parcel; //导入方法依赖的package包/类
public void save() {
Parcel p = Parcel.obtain();
try {
writeMagic(p);
p.writeInt(getCurrentVersion());
writePersistenceData(p);
FileOutputStream fos = new FileOutputStream(mPersistenceFile);
fos.write(p.marshall());
fos.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
p.recycle();
}
}
示例11: 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;
}
示例12: sizeAsParcel
import android.os.Parcel; //导入方法依赖的package包/类
/**
* Measure the size of a typed {@link Bundle} when written to a {@link Parcel}.
*
* @param bundle to measure
* @return size when written to parcel in bytes
*/
public static int sizeAsParcel(@NonNull Bundle bundle) {
Parcel parcel = Parcel.obtain();
try {
parcel.writeBundle(bundle);
return parcel.dataSize();
} finally {
parcel.recycle();
}
}
示例13: 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;
}
示例14: skipToQueueItem
import android.os.Parcel; //导入方法依赖的package包/类
public void skipToQueueItem(long id) throws RemoteException {
Parcel _data = Parcel.obtain();
Parcel _reply = Parcel.obtain();
try {
_data.writeInterfaceToken(Stub.DESCRIPTOR);
_data.writeLong(id);
this.mRemote.transact(17, _data, _reply, 0);
_reply.readException();
} finally {
_reply.recycle();
_data.recycle();
}
}
示例15: registerCallbackListener
import android.os.Parcel; //导入方法依赖的package包/类
public void registerCallbackListener(IMediaControllerCallback cb) throws RemoteException {
Parcel _data = Parcel.obtain();
Parcel _reply = Parcel.obtain();
try {
_data.writeInterfaceToken(Stub.DESCRIPTOR);
_data.writeStrongBinder(cb != null ? cb.asBinder() : null);
this.mRemote.transact(3, _data, _reply, 0);
_reply.readException();
} finally {
_reply.recycle();
_data.recycle();
}
}