views:

132

answers:

1

I am running into a very strange situation when using the PackageManager.getInstalledPackages() method. The first time I launch my activity I get a valid list of all the installed packages. But the second time I launch my activity I get an empty list... What could possibly be causing this?

I am using this code to get the list: List pkgList = getPackageManager().getInstalledPackages(PackageManager.GET_ACTIVITIES);

I am building against the 1.6 SDK with compatibility for 1.5+

Thanks in advance for any suggestions/help... I'm really baffled as to the cause and can't think of what I'm doing wrong.

+1  A: 

Perhaps the PackageManager needs to be invoked on the main application thread, for some reason. I haven't tried using it from an AsyncTask.

CommonsWare
That is the only thing I could think of... If that is the case though, it should probably be documented. I at least have a workaround, even though my initialization takes a little longer than I would like because I have to get the list of installed applications on the main thread.
Justin
@Justin: I wouldn't expect `getInstalledPackages()` itself to take very long, though perhaps it does. You could do that in `onPreExecute()` of your `AsyncTask` and the rest of the initialization work in `doInBackground()`. With respect to docs, I agree -- if you can create a sample project demonstrating the problem, post an issue to http://b.android.com with the sample and ask for a documentation update or a bug fix (in case it *should* work on a background thread).
CommonsWare
I forgot about the onPreExecute() method. I'll try using that and seeing what behavior I get. After your comment on the getInstalledPackages, I think you are right... the slowdown must be somewhere else. I'll see what I can do to get a sample project together. Thanks for the help.
Justin