There is a 1MB limit on a Binder transaction, which means most IPC invocations have to be modest in size.
If you hit a TransactionTooLargeException
or similar Binder failures when retrieving data from PackageManager
(e.g., getPackageInfo()
), try splitting your request over multiple calls, with fewer flags (e.g., GET_META_DATA
) per call. Hopefully this will reduce the size of any individual transaction to be under the 1MB limit.
Also, if you are using calls on PackageManager
that return multiple results (e.g., getInstalledPackages()
, try asking for no flags on that call, then retrieving the values for each package individually, to avoid getting a lot of data on a lot of entries at once.
And, of course, only use flags that you need, particularly if your call might contain some. GET_META_DATA
is a classic example of that: many apps use it (e.g., for Play Services), but if you do not need to know the metadata information, don't request it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…