简体   繁体   中英

most efficient way(load speed-performance i mean) to get a list of installed apps on android?

I developed an app with an activity that shows a listview of the installed apps, each row with icon, app label and checkbox. The app works fine on my nexus one and other device, but on some device, like for example an htc legend(froyo), it is extremely slow(1 minute before the activity comes up with the listview).

First i call the app list:

private String[] getAppList(){
        ArrayList<String> results=new ArrayList<String>();

        PackageManager pm = this.getPackageManager();

        List<ApplicationInfo> list = pm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES); 
        Collections.sort(list, new ApplicationInfo.DisplayNameComparator(pm));

        boolean includeSystemApps = getIntent().getBooleanExtra("sysapps",false);

        for (ApplicationInfo AppInfo : list) 
        {
              try
              {           
                  if(includeSystemApps || ((AppInfo.flags & ApplicationInfo.FLAG_SYSTEM)!=1))
                  {
                      results.add(AppInfo.packageName);
                  }
              }
              catch(Exception ex)
              {

              }
        } 

        return (String[])results.toArray(new String[results.size()]);
    }

Then, in the listview item adapter I load icon and label:

String Applabel;
        try 
        {
            Applabel=pk.getApplicationLabel(pk.getApplicationInfo(data[position], 0)).toString();
        }
        catch(Exception ex)
        {
            Applabel=data[position];
        }

        holder.text.setText(Applabel);
        holder.text.setHint(data[position]);
        holder.image.setTag(data[position]);

        try
        {
            holder.image.setImageBitmap(((BitmapDrawable)pk.getApplicationIcon(data[position])).getBitmap());
        }
        catch(Exception ex)
        {
        }

I think the long load time, on some device, is given by this call:

this.getPackageManager()

Now I don't think it's an hardware issue(cpu-ram) because the legend it's not a bad device at all.

But there are the crude data:

-nexus one(gingerbred) activity load ~1second

-legend(froyo) activity load ~40/60 secs!

Any suggestion/opinion? Thanks in advance

This will be due to the Android setup and hardware on the device. The best thing would be to move your loading into an AsyncTask an run it with a ProgressDialog of something like "Please wait, this could take a while"

Joe

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM