Android開發Error(建議收藏下來以備不時之需)android.os.TransactionTooLargeException: data p...
前言
該異常觸發的概率不大,很多Android猴子可能都沒遇到過
但是真的出現的時候別不知道怎麼解決
什麼情況出現
介面跳轉intent 中的資料內容較多
Android呼叫系統裁減圖片
批量插入大量資料到資料庫(我是這種情況,一下主要針對批量插入資料庫講解)
系統原始碼
原始碼位置:android/frameworks/base/core/jni/android_util_Binder.cpp
是的你沒看錯,在以上三種傳輸中大於200K就會報錯
case FAILED_TRANSACTION: { ALOGE("!!! FAILED BINDER TRANSACTION !!!(parcel size = %d)", parcelSize); const char* exceptionToThrow; char msg[128]; // TransactionTooLargeException is a checked exception, only throw from certain methods. // FIXME: Transaction too large is the most common reason for FAILED_TRANSACTION //but it is not the only one.The Binder driver can return BR_FAILED_REPLY //for other reasons also, such as if the transaction is malformed or //refers to an FD that has been closed.We should change the driver //to enable us to distinguish these cases in the future. if (canThrowRemoteException && parcelSize > 200*1024) {--------- 在這裡是有判斷的 // bona fide large payload exceptionToThrow = "android/os/TransactionTooLargeException"; snprintf(msg, sizeof(msg)-1, "data parcel size %d bytes", parcelSize); } else { // Heuristic: a payload smaller than this threshold "shouldn't" be too // big, so it's probably some other, more subtle problem.In practice // it seems to always mean that the remote process died while the binder // transaction was already in flight. exceptionToThrow = (canThrowRemoteException) ? "android/os/DeadObjectException" : "java/lang/RuntimeException"; snprintf(msg, sizeof(msg)-1, "Transaction failed on small parcel; remote process probably died"); } jniThrowException(env, exceptionToThrow, msg); } break;
解決方案
intent傳遞的資料過大把大型的序列化集合或者Bitmap快取傳遞快取路徑即可
Android呼叫系統裁減圖片 Bitmap 過大這個時候只能通過MediaStore.EXTRA_OUTPUT設定裁減圖片儲存位置,只傳遞圖片路徑,不直接傳bitmap物件。
批量插入大量資料到資料庫改成分多批根據自己實際資料量 去衡量每次批量傳入多少合適比如要批量傳入100000條資料每張表的資料還特別多可以以500條為一批按批插入