13

I got mail from a user who has a lot of apps installed that he has problems when my app gathers activity info with this code:

getPackageManager().queryIntentActivities(mAinIntent, 0)

whole source here: https://github.com/ligi/FAST

this is what happens

Caused by: java.lang.RuntimeException: Package manager has died
at android.app.ApplicationPackageManager.queryIntentActivities(ApplicationPackageManager.java:479)
at org.ligi.fast.BaseAppGatherAsyncTask.doInBackground(BaseAppGatherAsyncTask.java:34)
at org.ligi.fast.BaseAppGatherAsyncTask.doInBackground(BaseAppGatherAsyncTask.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
... 5 more
Caused by: android.os.TransactionTooLargeExceptionTransactionTooLargeException
at android.os.BinderProxy.transact(Native Method)
at android.content.pm.IPackageManager$Stub$Proxy.queryIntentActivities(IPackageManager.java:2230)
at android.app.ApplicationPackageManager.queryIntentActivities(ApplicationPackageManager.java:473)
... 9 more
Log:
0 D: Writing unhandled exception to: /data/data/org.ligi.fast/files/3.7-1364933885194.tracedroid

there seems to be a problem that I am running against the 1mb border, but how to get out of there? How else can I get the needed info? Is there a way to chunk up the data?

ligi
  • 39,001
  • 44
  • 144
  • 244
  • 1
    Is that a typo `TransactionTooLargeExceptionTransactionTooLargeException`? [See this](http://developer.android.com/reference/android/os/TransactionTooLargeException.html) *The Binder transaction buffer has a limited fixed size, currently 1Mb, which is shared by all transactions in progress for the process. Consequently this exception can be thrown when there are many transactions in progress even when most of the individual transactions are of moderate size.* – t0mm13b Apr 02 '13 at 21:22
  • `AppInfo` class, `private BitmapDrawable icon; ` ... are they eating up too much memory? Why are you passing multiple copies of `Contexts` from inside the AsyncTask? – t0mm13b Apr 02 '13 at 21:26
  • yea - seems to be a c&p'o - no clue how this doubled up. Do you see a workaround for the problem? – ligi Apr 02 '13 at 21:26
  • Thing is, if its scanning all apps, app's icons vary in sizes, that could be it, perhaps using `WeakReference` to the bitmap? Sounds like the class `AppInfo` would need to be optimized... – t0mm13b Apr 02 '13 at 21:28
  • how would that reduce the size of this transaction? I really do not think that would help .. – ligi Apr 02 '13 at 21:29
  • Was it Dianne Hackborn that mentioned it would be more efficient to use Drawables rather than bitmaps [https://groups.google.com/forum/#!topic/android-developers/KKEyW6XdDvg] See that example from newsgroup... and also [here](http://android-developers.blogspot.com/2009/01/avoiding-memory-leaks.html) See this [SO Question](http://stackoverflow.com/questions/7536988/android-app-out-of-memory-issues-tried-everything-and-still-at-a-loss)... Am concerned that you're holding *multiple copies of context* and bitmaps.. – t0mm13b Apr 02 '13 at 23:18
  • 1
    @t0mm13b I agree with @ligi. I fail to see how this exception when calling `queryIntentActivities` has anything to do with drawable sizes. @ligi, unfortunately I suspect you're out of luck. There's no paging mechanism or anything like that for `PackageManager` calls. – kabuko Apr 03 '13 at 01:49

1 Answers1

8

I ran into this error a while ago with the same user input. Though my thrown event was different. I ended up catching the exception and reporting back the user gracefully that there were too many apps installed with the ability to handle . Out of several hundred thousand installs I have only seen this error off-handedly less than five times for a project, I know that isn't an excuse but some devices just don't have the heap to handle indexing the intents of each application installed on the device.

BajaBob
  • 2,643
  • 3
  • 24
  • 26