PackageInfo LoadLabel性能下降 [英] PackageInfo LoadLabel slow performance
问题描述
我编码为Android,在那里获得应用程序的标签(实际名称)的应用程序是extremelly缓慢。特别是这个code正在执行实在太差了:
I am coding an app for Android, where getting a label (actual name) of the application is extremelly slow. Particularly this code is performing really badly:
packageInfo.loadLabel(pm);
只是为了给你一些指标。在具有400安装的应用程序的Android设备,它会采取不到一秒钟,建成所有应用packagenames列表(com.android *等)。但是,它会采取超过30秒,得到实际名称为每个应用程序。
Just to give you some metrics. On an Android device with 400 installed applications, it'll take less than a second to build a list of all application packagenames (com.android.*, etc..). However, it'll take over 30 seconds to get an actual name for each of the apps.
我已经试过这code为好,但它的pretty的大致相同的结果(很慢):
I've tried this code as well, but it's pretty much the same result (very slow):
(String)pm.getApplicationLabel(packageInfo);
问:如果应用程序软件包名是已知的(即com.android.htmlviewer),在那里抢到一个应用程序名称(如HTML浏览器)快速的另一种方式。
Question: If application packagename is known (i.e. "com.android.htmlviewer"), is there an alternative way to grab an application name (i.e. "HTML Viewer") quickly?
推荐答案
您可以建立在你的已知的应用程序名称应用程序的数据库,每一个您的应用程序遇到一个新的包时更新。第一次运行,通过将需要一段时间,但在那之后,你可以通过只检查一个或两个包名节省了大量的时间。
You could build a database in your app of "known" application names, and update it every time your app comes across a new package. The first run through will take a while, but after that you could save a lot of time by only checking one or two package names.
这篇关于PackageInfo LoadLabel性能下降的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!