The intention to install the installed application is slow in my activities, why?

If you click on your desktop for a long time and choose to add an application shortcut, you will be greeted with a list that will show all your applications for installation. I needed the same functionality in my application, so I copied the intent from the launch source:

        Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);            
        Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
        pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
        this.startActivityForResult(pickIntent, MoreIconsConstants.REQUEST_PICK_APPLICATION)

When this is done in the launcher, it is pretty fast. When I do this in my activity, it takes maybe 15 seconds instead of 3. It seems that the launcher should cache this data for some time? Is there a way to cache data?

Thank!

+3
source share
1 answer

,

final PackageManager pm = a.getPackageManager();

    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    final List<ResolveInfo> apps = pm.queryIntentActivities(mainIntent, 0);
    Collections.sort(apps, new ResolveInfo.DisplayNameComparator(pm));

    for (int i = 0; i < apps.size(); i++) 
    {
        ResolveInfo info = apps.get(i);
       //Intent to start the app
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setComponent(new ComponentName(info.activityInfo.applicationInfo.packageName,info.activityInfo.name));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        //Load app icon
        info.activityInfo.loadIcon(pm)
        //Load app label
        info.loadLabel(pm)
}

http://developer.android.com/resources/samples/Home/src/com/example/android/home/Home.html loadApplications

, .

+2

Source: https://habr.com/ru/post/1727415/


All Articles