What to do on TransactionTooLargeException

前端 未结 30 3393
盖世英雄少女心
盖世英雄少女心 2020-11-22 03:08

I got a TransactionTooLargeException. Not reproducible. In the docs it says

The Binder transaction failed because it was too large.

D

30条回答
  •  遥遥无期
    2020-11-22 03:39

    It is important to understand that the transaction buffer is limited to 1 MB, regardless of device capabilities or app. This buffer is used with every API calls you make and is shared amongst all transactions an app is currently running.

    I believe it also holds some specific object like parcels and such (Parcel.obtain()), so it's important to always match every obtain() with a recycle().

    This error can easily happen on API calls returning a lot of data, even though the returned data is less than 1 MB (if other transactions are still running).

    For example, the PackageManager.getInstalledApplication() call returns a list of all apps installed. Adding specific flags allows to retrieve a lot of extra data. Doing so is likely to fail, so it's recommended not to retrieve any extra data and retrieve those on a per-app basis.

    However the call may still fail, so it's important to surround it with a catch and be able to retry if necessary.

    As far as I know, there's no work-around to such issue except retrying and making sure to retrieve as little information as possible.

提交回复
热议问题