Android 7.0出现android.os.TransactionTooLargeException崩溃求解析
android.os.TransactionTooLargeException on Android 7.0 (Bundle < 1MB) Hey there, let's break down this tricky crash you're hitting. Even though you've verified your Intent/Service Bundles are under 1MB, there are several less obvious culprits to investigate for this exception on Android 7.0:
Possible Hidden Causes
Accumulated system + app state data
The 1MB Binder transaction limit applies to the total data in a single transaction, not just your explicit Intent payload. For example, when launching an Activity or saving instance state, the system adds its own data (like configuration details, recent app metadata, or saved fragment state) to the transaction. If your app's data is already close to 1MB, this extra system data can push it over the edge.Parcelable overhead you're not accounting for
Don't just trust your rough size calculations—Parcelableobjects often have hidden overhead. A list of custom Parcelables might store extra metadata, or types like styledCharSequenceor compressedBitmapcan balloon in size when parceled. To get the real byte count, log the size of your Parcel after writing objects withparcel.dataSize()before sending it.Fragment back stack bloat
If your app uses Fragments, each entry in the back stack saves state data that gets passed via Binder during transactions. Even small individual fragment state can add up across multiple stack entries, especially if you're not clearing the back stack when it's no longer needed. Check if crashes correlate with fragment navigation or large back stacks.Unintended objects in saved state
Memory leaks or accidental references can cause large objects to sneak intoonSaveInstanceStatebundles. For example, a leaked reference to a large bitmap or a cached dataset might get parceled alongside your intended state data. Use Android Studio's Memory Profiler to audit what's being stored in your Bundles.Back-to-back small transactions
The Binder has a cumulative buffer, not just per-transaction limits. If you're sending multiple small transactions in rapid succession (e.g., multiple Intent broadcasts or service calls), the combined unprocessed data can exceed the total buffer size. Try adding small delays between transactions or splitting bulk operations into smaller chunks.
Debugging Tips
- Use
adb shell dumpsys activityto inspect recent transactions for your app. Look for entries showing transaction sizes to pinpoint which component is causing the overflow. - Override
onSaveInstanceStatein your Activities/Fragments and logbundle.size()to track if saved state is growing unexpectedly over time. - Test with a stripped-down version of your app: remove non-essential features to isolate which part of your code is contributing to the large transaction.
内容的提问来源于stack exchange,提问作者anthony

