Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Getting list of device applications - Very Slow

Tags:

android

list

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;
}
like image 416
jjj Avatar asked Nov 30 '12 01:11

jjj


1 Answers

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.

like image 177
terra Avatar answered Sep 25 '22 09:09

terra