I need to get a list of all the applications installed on the device, within 5-10 seconds after the user opens my application.
This is because it takes approx. 5-10 seconds for a regular user of my Android application to request information about applications installed on the device.
To be relevant, I have to create a new copy of the list of installed applications every time my application loads.
However, using the code below, it takes more than 30 seconds on a quad-core Android device with approx. 400 applications (system and installed - I need both).
I had code executing in 'on create', but no one would wait 30 seconds to open the application. So I moved it to AsyncTask so that my application opens immediately. But still it takes +30 seconds; and if someone asks for a specific application before downloading the list, they may not receive the correct information.
Why is this code so slow? And what can I do to speed it up? I will pay gold to anyone who can do it 10 times faster or give me good advice.
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; }
jjj
source share