[JAVA] [Android] Cause and remedy for TransactionTooLargeException

Event

The following errors are measured on Android.

Fatal Exception: java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 3181388 bytes
       at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3950)
       at android.os.Handler.handleCallback(Handler.java:790)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6501)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

Cause

If you have a large data of 1MB or more in the intent, you may get this error and crash.

approach

It is difficult to know where the crash is from the error message. Use ʻonSaveInstanceState to identify areas such as .putExtra / .getExtraand.putParcelable / .getParcelable`, and deal with areas where 1MB or more is likely to be set.

The target data is temporarily saved in a file at the timing of ʻonPause, and then recalled and expanded at the timing of ʻonResume. If you want to save to a file, you may want to keep the path in an intent and delete it with ʻonDestroy`.

Recommended Posts

[Android] Cause and remedy for TransactionTooLargeException
[Android] Change the app name and app icon for each Flavor
About for statement and if statement
default value for android: exported
Remedy for Selenium InvalidSelectorException error
Scheduler for RxAndroid and RxSwing
Build Spring for Android 2.0.0 environment
Java while and for statements
Intel Multi-OS Engine (MOE), a cross-platform library for Android and iOS
[Android Studio] [For beginners] Let's roughly explain the screen and directories
Introduction to Android App Development 1 Installing JDK and Android Studio for mac