本文整理汇总了Java中android.os.Parcel.writeException方法的典型用法代码示例。如果您正苦于以下问题:Java Parcel.writeException方法的具体用法?Java Parcel.writeException怎么用?Java Parcel.writeException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.Parcel
的用法示例。
在下文中一共展示了Parcel.writeException方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeExceptionToParcel
import android.os.Parcel; //导入方法依赖的package包/类
/**
* Special function for writing an exception result at the header of
* a parcel, to be used when returning an exception from a transaction.
* exception will be re-thrown by the function in another process
*
* @param reply Parcel to write to
* @param e The Exception to be written.
* @see Parcel#writeNoException
* @see Parcel#writeException
*/
public static final void writeExceptionToParcel(Parcel reply, Exception e) {
int code = 0;
boolean logException = true;
if (e instanceof FileNotFoundException) {
code = 1;
logException = false;
} else if (e instanceof IllegalArgumentException) {
code = 2;
} else if (e instanceof UnsupportedOperationException) {
code = 3;
} else if (e instanceof SQLiteAbortException) {
code = 4;
} else if (e instanceof SQLiteConstraintException) {
code = 5;
} else if (e instanceof SQLiteDatabaseCorruptException) {
code = 6;
} else if (e instanceof SQLiteFullException) {
code = 7;
} else if (e instanceof SQLiteDiskIOException) {
code = 8;
} else if (e instanceof SQLiteException) {
code = 9;
} else if (e instanceof OperationApplicationException) {
code = 10;
} else if (e instanceof OperationCanceledException) {
code = 11;
logException = false;
} else {
reply.writeException(e);
Log.e(TAG, "Writing exception to parcel", e);
return;
}
reply.writeInt(code);
reply.writeString(e.getMessage());
if (logException) {
Log.e(TAG, "Writing exception to parcel", e);
}
}
示例2: writeExceptionToParcel
import android.os.Parcel; //导入方法依赖的package包/类
public static final void writeExceptionToParcel(Parcel reply, Exception e) {
if (e instanceof DeviceUnavailableException) {
reply.writeInt(1);
reply.writeString(e.getMessage());
if (true) {
Log.e(TAG, "Writing exception to parcel", e);
return;
}
return;
}
reply.writeException(e);
Log.e(TAG, "Writing exception to parcel", e);
}
示例3: callMethod
import android.os.Parcel; //导入方法依赖的package包/类
public void callMethod(final String className, final String serviceName,
final String methodName, final Object... paramsAndListener) {
Parcel data = Parcel.obtain();
data.writeInterfaceToken(className);
for (int i = 0; i < paramsAndListener.length - 1; i++) {
Object p = paramsAndListener[i];
if (p instanceof Byte)
data.writeByte((Byte) p);
else if (p instanceof Integer)
data.writeInt((Integer) p);
else if (p instanceof Long)
data.writeLong((Long) p);
else if (p instanceof String)
data.writeString((String) p);
else if (p instanceof Bundle)
data.writeBundle((Bundle) p);
else if (p instanceof Float)
data.writeFloat((Float) p);
else if (p instanceof FileDescriptor)
data.writeFileDescriptor((FileDescriptor) p);
else if (p instanceof List)
data.writeList((List) p);
else if (p instanceof Exception)
data.writeException((Exception) p);
else if (p instanceof IBinder)
data.writeStrongBinder((IBinder) p);
else if (p instanceof Double)
data.writeDouble((Double) p);
else if (p instanceof Map)
data.writeMap((Map) p);
else if (p instanceof boolean[])
data.writeBooleanArray((boolean[]) p);
else if (p instanceof byte[])
data.writeByteArray((byte[]) p);
else if (p instanceof char[])
data.writeCharArray((char[]) p);
else if (p instanceof int[])
data.writeIntArray((int[]) p);
else if (p instanceof IBinder[])
data.writeBinderArray((IBinder[]) p);
else if (p instanceof double[])
data.writeDoubleArray((double[]) p);
else if (p instanceof Object[])
data.writeArray((Object[]) p);
else data.writeValue(p);
}
Object lastParam = paramsAndListener[paramsAndListener.length - 1];
CallMethodResultListener listener = lastParam == null ? null :
(CallMethodResultListener) lastParam;
callMethod(className, serviceName, methodName, data, listener);
data.recycle();
}