On Sep 18, 9:13 am, Peli <
peli0...@googlemail.com> wrote:
> 1) Sometimes there are several ways to do the same thing, like VIEW
> and EDIT call exactly the same activity with same functionality, or
> GET_CONTENT or PICK do essentially the same. Does it make sense to
> duplicate all explanation for these entries in the database? Should
> they be collected? Or should developers rather be advised to only
> provide a single interface, to simplify future maintainability? (or is
> the philosophy rather the opposite, to provide as many scheme / action
> combinations as possible?)
As far as VIEW and EDIT go, they are defined to do different things,
so they are indeed different. Of course, VIEW is used all over the
place, and EDIT is used much less frequently. But still -- VIEW means
to present the user a UI for viewing the given data, and EDIT means to
present the user a UI for editing it. It is not at all unexpected
that the same activity could implement both, and look at the intent
action to adjust its UI to do what is being asked (or even just be a
general purpose UI that does both intrinsically).
GET_CONTENT and PICK are even more distinct: the entire protocol for
them is different. PICK is given a URI and allows the user to pick
from some data in there which is returned as the result intent data.
GET_CONTENT is given a MIME type of the data you would like, shows the
user a UI for browsing through that type of data managed by the
activity, and returns the selection as the result intent data.
As with VIEW and EDIT, GET_CONTENT is much more common than PICK
(although in the current applications this is not reflected well
because GET_CONTENT was added quite a bit later than PICK when we
found the PICK protocol usually wasn't what we really wanted).
> 2) Most of the time, the action is one of the standard actions VIEW,
> EDIT, PICK, so should they actually go into a separate table "action",
> with id and action?
We should be documenting intent -protocols-. That is, VIEW is a
protocol, and there should only be one entry for it. The VIEW
protocol is:
- An activity implementing this action will display to the user the
given data. It is not intended for the user to edit it, though an
implementation can allow that to be done as a secondary part of its UI
if desired (as it can provide any other optional features in its UI
for the user).
- The action is mumblemumble.VIEW
- A data Uri must be supplied giving what to view.
- No result is returned.
Likewise, EDIT, GET_CONTENT, and PICK each have their own well-defined
protocols, as documented in the Intent class.
> 3) "scheme" in the Android sense is only the first part of the URI,
> but in the table, the whole URI is put there. Should a database rather
> contain a strict representation of the intents and store
> scheme="flickr" host="photos", or be more user-friendly and store
> scheme="flickr://photos"?
First, the scheme shown here is not appropriate. As far as I know,
there is no standard "flickr" protocol defined (what would that
protocol do?), and so people should not be making up such a thing in
their app. And it is really not useful to do this, because if for
example you wanted to use this with GET_CONTENT or PICK... well,
nobody else knows what to do with a "flickr" scheme (none of the
ContentResolver API would work on it -- from getting MIME types to
opening data streams), so it wouldn't work.
If you want to have a specific Intent that can be invoked to, say, a
Flickr photo viewer, you would define your own action for it, such as
com.mydomain.action.VIEW_FLICKR, and that is what would be registered.
Intent actions are the primary mechanism for introducing new classes
of functionality. There is no reason to get tricky with schemes or
URIs or MIME types for that. Just define an action. That's what
they're for, and there's an infinite supply of the. ;)
> 4) With the "extras", the table structure can get really messy:
> Sometimes there are extras as input, sometimes extras as output,
> sometimes input extras and output extras agree, sometimes they
> disagree. Should they be described as text only in the description?
> Would there be any use for storing them in a more rigid structure
> (separate table for extras)?
My preference would be to have a separate table of extras, which an
Intent protocol would reference. This is because there are two main
ways you use extras:
(1) As required or intrinsic option parameters that go along with the
Intent. This is, when you define a particular protocol, you say "and
the caller must supply extra X and optionally extra Y in the starting
Intent, and the result must contain extra Z."
(2) As additional optional features that can be included with existing
protocols. For example, I may write my Super Contact Viewer, that
replaces the built-in contact views with the same protocol, but has
additional features. I can define new intent extras that callers can
optionally supply when starting a contact viewer, and they can include
these extras so that if my activity (or someone else's activity also
supporting the features) is the one that runs, it will do these
advanced things.
Because of this, like the action names, the extra names should be a
unique, global namespace, allowing them to be mixed and matched with
any protocol as appropriate.
The same follows for categories. The category names allow you to
specify filtering requirements -- for example, you can use GET_CONTENT
by itself to run anything that can select a content: URI, or you can
add in the OPENABLE category to only run those things that will return
a content: URI that can be opened. In fact these two were not defined
at the same time -- we first defined GET_CONTENT, then later realized
we needed to filter the available activities down in some cases, so
introduced the new OPENABLE category as add additional requirement you
can make when using GET_CONTENT. That category could just as well be
used with other actions where it makes sense (PICK possibly), even
though it was originally defined for the needs of GET_CONTENT. So
likewise, we should keep the categories in their own, unique
namespace.
We can also talk the same way about MIME types. People often want to
define their own MIME types for data types, and doing so does not mean
defining a bunch of new Intent protocols: it usually is just be a new
type you can use with the existing protocols. I think this more
properly belongs with defining content providers, though, since
usually defining a MIME type means also defining all of the cursor
rows and such that go along with it.
Finally, a little more on schemes. Though we do use schemes in some
select places for special actions (such as mailto:), this is always
being done with schemes defined by existing standards (most
importantly to be able to supply that functionality for the user
clicking on links in the web browser), and we always try to also
define an official action name for the same function. People
shouldn't be introducing new intent protocols by making up their own
schemes, though of course if you want to provide an implementation for
an existing standard scheme that is quite reasonable.