本文整理匯總了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();
}