本文整理汇总了Java中android.content.Intent.writeToParcel方法的典型用法代码示例。如果您正苦于以下问题:Java Intent.writeToParcel方法的具体用法?Java Intent.writeToParcel怎么用?Java Intent.writeToParcel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.Intent
的用法示例。
在下文中一共展示了Intent.writeToParcel方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startActivity
import android.content.Intent; //导入方法依赖的package包/类
public void startActivity(String deviceId, Intent intent) throws RemoteException {
Parcel _data = Parcel.obtain();
Parcel _reply = Parcel.obtain();
try {
_data.writeInterfaceToken(Stub.DESCRIPTOR);
_data.writeString(deviceId);
if (intent != null) {
_data.writeInt(1);
intent.writeToParcel(_data, 0);
} else {
_data.writeInt(0);
}
this.mRemote.transact(11, _data, _reply, 0);
ExceptionUtils.readExceptionFromParcel(_reply);
} finally {
_reply.recycle();
_data.recycle();
}
}
示例2: sendBroadcast
import android.content.Intent; //导入方法依赖的package包/类
public void sendBroadcast(String deviceId, Intent intent) throws RemoteException {
Parcel _data = Parcel.obtain();
Parcel _reply = Parcel.obtain();
try {
_data.writeInterfaceToken(Stub.DESCRIPTOR);
_data.writeString(deviceId);
if (intent != null) {
_data.writeInt(1);
intent.writeToParcel(_data, 0);
} else {
_data.writeInt(0);
}
this.mRemote.transact(12, _data, _reply, 0);
ExceptionUtils.readExceptionFromParcel(_reply);
} finally {
_reply.recycle();
_data.recycle();
}
}
示例3: onPackageChange
import android.content.Intent; //导入方法依赖的package包/类
public void onPackageChange(String deviceId, Intent intent) throws RemoteException {
Parcel _data = Parcel.obtain();
Parcel _reply = Parcel.obtain();
try {
_data.writeInterfaceToken(Stub.DESCRIPTOR);
_data.writeString(deviceId);
if (intent != null) {
_data.writeInt(1);
intent.writeToParcel(_data, 0);
} else {
_data.writeInt(0);
}
this.mRemote.transact(5, _data, _reply, 0);
_reply.readException();
} finally {
_reply.recycle();
_data.recycle();
}
}
示例4: initBroadcastParcel
import android.content.Intent; //导入方法依赖的package包/类
@SuppressLint("Recycle")// when process dead, we should save time to restart and kill self, don`t take a waste of time to recycle
private void initBroadcastParcel(Context context, String broadcastName){
Intent intent = new Intent();
ComponentName componentName = new ComponentName(context.getPackageName(), broadcastName);
intent.setComponent(componentName);
intent.setFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
/*
// Object contextImpl = ((Application)context.getApplicationContext()).getBaseContext();
//this context is ContextImpl, get MainThread instance immediately
Field mainThreadField = context.getClass().getDeclaredField("mMainThread");
mainThreadField.setAccessible(true);
Object mainThread = mainThreadField.get(context);
//get ApplicationThread instance
Object applicationThread = mainThread.getClass().getMethod("getApplicationThread").invoke(mainThread);
//get Binder
Binder callerBinder = (Binder) (applicationThread.getClass().getMethod("asBinder").invoke(applicationThread));
*/
// UserHandle userHandle = android.os.Process.myUserHandle();
// int handle = (Integer) userHandle.getClass().getMethod("getIdentifier").invoke(userHandle);
mBroadcastData = Parcel.obtain();
mBroadcastData.writeInterfaceToken("android.app.IActivityManager");
// mBroadcastData.writeStrongBinder(callerBinder);
mBroadcastData.writeStrongBinder(null);
intent.writeToParcel(mBroadcastData, 0);
mBroadcastData.writeString(intent.resolveTypeIfNeeded(context.getContentResolver()));
mBroadcastData.writeStrongBinder(null);
mBroadcastData.writeInt(Activity.RESULT_OK);
mBroadcastData.writeString(null);
mBroadcastData.writeBundle(null);
mBroadcastData.writeString(null);
mBroadcastData.writeInt(-1);
mBroadcastData.writeInt(0);
mBroadcastData.writeInt(0);
// mBroadcastData.writeInt(handle);
mBroadcastData.writeInt(0);
}
示例5: initServiceParcel
import android.content.Intent; //导入方法依赖的package包/类
@SuppressLint("Recycle")// when process dead, we should save time to restart and kill self, don`t take a waste of time to recycle
private void initServiceParcel(Context context, String serviceName){
Intent intent = new Intent();
ComponentName component = new ComponentName(context.getPackageName(), serviceName);
intent.setComponent(component);
/*
//get ContextImpl instance
// Object contextImpl = ((Application)context.getApplicationContext()).getBaseContext();
//this context is ContextImpl, get MainThread instance immediately
Field mainThreadField = context.getClass().getDeclaredField("mMainThread");
mainThreadField.setAccessible(true);
Object mainThread = mainThreadField.get(context);
//get ApplicationThread instance
Object applicationThread = mainThread.getClass().getMethod("getApplicationThread").invoke(mainThread);
//get Binder
Binder callerBinder = (Binder) (applicationThread.getClass().getMethod("asBinder").invoke(applicationThread));
*/
//get handle
// UserHandle userHandle = android.os.Process.myUserHandle();
// int handle = (Integer) userHandle.getClass().getMethod("getIdentifier").invoke(userHandle);
//write pacel
mServiceData = Parcel.obtain();
mServiceData.writeInterfaceToken("android.app.IActivityManager");
mServiceData.writeStrongBinder(null);
// mServiceData.writeStrongBinder(callerBinder);
intent.writeToParcel(mServiceData, 0);
mServiceData.writeString(null);
// mServiceData.writeString(intent.resolveTypeIfNeeded(context.getContentResolver()));
mServiceData.writeInt(0);
// mServiceData.writeInt(handle);
}
示例6: getParceledIntentSize
import android.content.Intent; //导入方法依赖的package包/类
/**
* Returns how large the Intent will be in Parcel form, which is helpful for gauging whether
* Android will deliver the Intent instead of throwing a TransactionTooLargeException.
*
* @param intent Intent to get the size of.
* @return Number of bytes required to parcel the Intent.
*/
public static int getParceledIntentSize(Intent intent) {
Parcel parcel = Parcel.obtain();
intent.writeToParcel(parcel, 0);
return parcel.dataSize();
}