Optimize call to queryIntentActivities()
Jean-Baptiste Queru [Sat, 28 Feb 2009 00:53:12 +0000 (16:53 -0800)]
Replace a call to queryIntentActivities() with a calls to
resolveActivity(). This is done since the only purpose of the call
is to check if the returned list is empty or non-empty. It's
inefficient to move an entire list across the process boundary,
only to discard it.

src/com/android/providers/downloads/Helpers.java

index 0226eba..866cddc 100644 (file)
@@ -38,7 +38,6 @@ import android.webkit.MimeTypeMap;
 import java.io.File; 
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
-import java.util.List;
 import java.util.Random;
 import java.util.Set;
 import java.util.regex.Matcher;
@@ -115,11 +114,10 @@ public class Helpers {
 
                 PackageManager pm = context.getPackageManager();
                 intent.setDataAndType(Uri.fromParts("file", "", null), mimeType);
-                List<ResolveInfo> list = pm.queryIntentActivities(intent,
-                        PackageManager.MATCH_DEFAULT_ONLY);
+                ResolveInfo ri = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
                 //Log.i(Constants.TAG, "*** FILENAME QUERY " + intent + ": " + list);
 
-                if (list.size() == 0) {
+                if (ri == null) {
                     if (Config.LOGD) {
                         Log.d(Constants.TAG, "no handler found for type " + mimeType);
                     }