문제

I am writing a launcher in Android and here is the problem I have been trying to fix for a while with no luck.

I have below code to query all activities running at very beginning of my launcher, say onResume().

final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List<ResolveInfo> infos = packageManager.queryIntentActivities(mainIntent, 0);
for (final ResolveInfo info : infos) {
    // create my own recrord for each activity      
}

The problem is that if I set my launcher as default and reboot the device, every time I can get only part of the full list by above code. It seems some big fat activities (such as Wind-up knight) are always missing. However running above code second time will return the full list. Does any one have idea why? My guess is that PackageManager needs some time to parse the fat activities and if queryIntentActivities() is called too early, it just returns a partial list, is that true?

But why doesn't the default launcher have this issue?

도움이 되었습니까?

해결책

Larger activities are more likely to be installed on the external storage partition, which can often take a while to be mounted. The launcher on my Samsung Galaxy W phone does exactly this, presenting a place-holder icon until the SD card is mounted and the app is ready to use.

There should be a broadcast from the PackageManager to tell you when a new crop of applications are available, but I couldn't find one at a glance. You may have to listen to ACTION_MEDIA_MOUNTED and hope the PackageManager has got there first.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top