问题描述
我遇到了一个非常奇怪的情况下使用PackageManager.getInstalledPackages()方法时。我第一次启动我的活动我得到的所有已安装的软件包的有效名单。但我第二次启动我的活动我得到一个空列表...怎么可能会导致这?
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?
我用这code,以获取列表:名单pkgList = getPackageManager()getInstalledPackages(PackageManager.GET_ACTIVITIES);
I am using this code to get the list:List pkgList = getPackageManager().getInstalledPackages(PackageManager.GET_ACTIVITIES);
我建立对1.6的SDK 1.5兼容+
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.
推荐答案
也许 PackageManager
需要在主应用程序线程上调用,出于某种原因。使用它,我没有尝试过的的AsyncTask
。
Perhaps the PackageManager
needs to be invoked on the main application thread, for some reason. I haven't tried using it from an AsyncTask
.
这篇关于PackageManager.getInstalledPackages()返回空列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!