在Android的UI线程操作过程中显示ProgressDialog [英] Showing ProgressDialog during UI Thread operation in Android
问题描述
在我asken已经将另一个问题这里似乎PackageManager.getInstalledPackages( )不与线程发挥好。由于CommonsWare说明<一个href=\"http://stackoverflow.com/questions/3455781/packagemanager-getinstalledpackages-returns-empty-list\">HERE:
As I've asken on another question HERE it seems that the PackageManager.getInstalledPackages() doesn't play nice with Threading. As CommonsWare stated HERE:
或许软件包管理系统需要在主应用程序被调用
螺纹,由于某种原因
Perhaps the PackageManager needs to be invoked on the main application thread, for some reason
因此,有它在一个线程得到意外的行为,并进入我的活动退出了几下,使显示的应用列表有时物品,有时是空的。在UI线程拥有一切就像一个梦,加载罚款每次。问题是,用户期望某种形式的反馈,我需要提供一个。当我开始活动时,屏幕保持黑色3-4-5-6秒(根据所安装的设备和应用程序上)。我怎么能提供某种反馈?我想到一个ProgressDialog的,但我不知道我怎么可以启动它。谢谢你。
So having it on a thread gets undesired behavior, entering and exiting a few times in my Activity makes the list of displayed apps sometimes with items, sometimes empty. Having everything in the UI Thread works like a dream, loads fine everytime. The thing is, the user expects some sort of feedback and I need to provide one. As I start the activity, the screen remains black for 3-4-5-6 seconds (depending on the device and apps installed). How can I provide some sort of feedback ? I am thinking of a ProgressDialog but I don't know how can I start it. Thank you.
推荐答案
如发现,在循环通过应用工作需要一段时间(其可以在一个单独的线程来实现),相比于呼叫到PackageManager.getInstalledPackages() (这必须要在UI线程上完成)。
As discovered, the loop to work through the applications takes awhile (which can be done in a separate thread), compared to the call to PackageManager.getInstalledPackages() (which has to be done on the UI thread).
这篇关于在Android的UI线程操作过程中显示ProgressDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!