Why is resolveInfo.loadLabel () so ridiculously slow?

In my desktop replacement application, I need to get a list of all installed applications to put them in the application box. Therefore, the following method is launched in each application:

public static App fromResolveInfo (Context context, PackageManager pacMan, AppManager appManager, ResolveInfo resInf) { String label = resInf.loadLabel (pacMan).toString (); String packageName = resInf.activityInfo.applicationInfo.packageName; String activityName = resInf.activityInfo.name; App app = new App (context, appManager); app.setLabel (label); app.setPackageName (packageName); app.setActivityName (activityName); AppIcon icon = null; if (appManager.isIconPackLoaded ()) icon = appManager.getIconPack ().getIconForApp (app); if (icon == null) icon = appManager.getIconPack ().getFallbackIcon (resInf.loadIcon (pacMan)); app.setIcon (icon); return app; } 

The problem is that there is a bottleneck here, and it does not load the icons, as I expected. The first line of the method ( String label = resInf.loadLabel (pacMan).toString (); ) can take from 0 to 250 milliseconds (at a relatively high level of the device). On older devices, this becomes a real problem.
In my tests, I noticed that when a slower device is multitasking, and for some reason the application box needs to be rebooted, this may take 30 seconds (for all installed applications).

Caching may offer a potential solution for this, but then what if the application name changes (what happens occasionally)? I would have to take tags from the cache, and then iterate over all the applications in a separate thread and fix the tags where they were changed. This may offer a solution, but it seems more like a dirty hack than a really good solution.

Is there a faster way to get an application activity shortcut? Also, why is it so ridiculously long for Android to get an application shortcut and / or is there anything I can do about it?

+5
source share
1 answer

You can get a shortcut like:

 String label = (String) resInf.activityInfo.applicationInfo.loadLabel(pacMan); 

If you are comparing the Android source code for these two methods, you will notice that the application from the Info application has less code to execute. Perhaps the bottleneck is in the extra code. I personally have never compared runtimes for those since I have never seen such a problem.

0
source

All Articles