2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Android]TransactionTooLargeException の原因と対処法

Last updated at Posted at 2019-04-07

事象

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)

原因

インテントに1MB以上の大きなデータを持たせると、このエラーが出てクラッシュする事がある。

対処法

エラーメッセージからは、どこでクラッシュしているかを知る事は困難。
onSaveInstanceState.putExtra/.getExtra.putParcelable/.getParcelable などしている箇所を洗い出し、1MB以上セットしていそうな箇所を対処する。

対象のデータは、 onPause のタイミングで一旦ファイルなどに退避し、 onResume のタイミングで再度呼び出して展開する。ファイルに退避する場合、そのパスをインテントに持っておいて、 onDestroy で削除するようにしておくと良いかもしれない。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?