9

I need to get the list of all apps installed on device within 5-10 seconds after user opens my app.

This is because, it takes approx. 5-10 seconds for a typical user of my android application, to request the info about apps installed on a device.

To be relevant, I have to create a fresh copy of the list of installed apps everytime my app is loaded.

However, using code below it takes over 30 seconds on a quad core Android device with approx. 400 apps (system and installed - I need both).

I had the code executing in 'on create' but no one would wait 30 seconds to open app. So I've moved it to AsyncTask, just so my app opens immediadetelly. But still, it takes +30 seconds; and if someone asks for a specific app before the list is loaded, they may not get the correct info.

Why is this code so slow? And what can I do to speed this up? I will pay in gold to anyone who can make it 10 times faster or give me a good tip.

final PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);

for (ApplicationInfo packageInfo : packages) {
    InstalledAppsName.add(packageInfo.loadLabel(pm).toString());
    CountApps=CountApps+1;
}
8
  • how quick does the full application list in the settings load on the same device?
    – FoamyGuy
    Nov 30, 2012 at 2:08
  • I've tested it using settings option (as you've suggested) on the same device and that is faster than the code above. Approximately 10-15 seconds to load. Still not ideal, but better. Any suggestions?
    – jjj
    Nov 30, 2012 at 2:39
  • Do you know which line of code needs the most time?
    – Uooo
    Nov 30, 2012 at 6:28
  • It's the loop which is taking the time.
    – jjj
    Nov 30, 2012 at 14:20
  • This specific line is causing an issue: InstalledAppsName.add(packageInfo.loadLabel(pm).toString());
    – jjj
    Nov 30, 2012 at 20:36

1 Answer 1

2

See PackageInfo LoadLabel slow performance

Getting the label is taking so long, because (I think) it needs to be loaded from the APK. You could in the meanwhile just show the package names and step by step replace it with the label.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.