4

I find it not so clear as to how getPreferredActivities works.

For example, can getPreferredActivities return more than one item in case I ask it to return the default app of specific type?

I think it's supposed to return the default activity for the filters it has, but the documentation doesn't say how it works:

Retrieve all preferred activities, previously added with addPreferredActivity(IntentFilter, int, ComponentName[], ComponentName), that are currently registered with the system.

Parameters
outFilters  A list in which to place the filters of all of the preferred activities, or null for none.
outActivities   A list in which to place the component names of all of the preferred activities, or null for none.
packageName An option package in which you would like to limit the list. If null, all activities will be returned; if non-null, only those activities in the given package are returned.
Returns
Returns the total number of registered preferred activities (the number of distinct IntentFilter records, not the number of unique activity components) that were found.

of course, if the filter has very few rules, it will probably return more than one item, but what if i ask it to return the default launcher(home app) , or the default web browser? or the default video player...?

For example, if I use this code, will it always return a list containing only 1 or 0 items?

android developer
  • 114,585
  • 152
  • 739
  • 1,270

0 Answers0