我在使用 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?
我正在使用此代码来获取列表:列出 pkgList = getPackageManager().getInstalledPackages(PackageManager.GET_ACTIVITIES);
I am using this code to get the list: List pkgList = getPackageManager().getInstalledPackages(PackageManager.GET_ACTIVITIES);
我正在构建与 1.5+ 兼容的 1.6 SDK
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
.
UPDATE 2018-03-26:PackageManager
通常可以在后台线程上调用,尤其是 getInstalledPackages()
.
UPDATE 2018-03-26: PackageManager
generally is fine to invoke on background threads, getInstalledPackages()
in particular.
这篇关于PackageManager.getInstalledPackages() 返回空列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!