Tuesday, May 11, 2010

Regular update, May 10th

Following section was Localization, which closed the Resources and Assets chapter. Next section is Intents and Intent Filters, which understanding is quite important for our application. I'll let myself collect a few lines of most interesting material. (By the way, if you some some wicked amount of new-lines in any post on this blog, it's some sort of blogger bug.. certainly, it's not a feature).

Useful action constant from Intent class:
ACTION_MAIN, target: activity; Start up as the initial activity of a task, with no data input and no returned output - app (i.e. activity) entry point
ACTION_SYNC, target: activity; Synchronize data on a server with data on the mobile device. - we would make sync service call that upon the app
ACTION_BATTERY_LOW, target: broadcast receiver; A warning that the battery is low - we could turn off data sync in such situations (defined in app settings)

The action in an Intent object is set by the setAction() method and read by getAction().
The setData() method specifies data only as a URI, setType() specifies it only as a MIME type, and setDataAndType() specifies it as both a URI and a MIME type. The URI is read by getData() and the type by getType().

Important categories:
CATEGORY_LAUNCHER - The activity can be the initial activity of a task and is listed in the top-level application launcher.
CATEGORY_PREFERENCE - The target activity is a preference panel.

The addCategory() method places a category in an Intent object, removeCategory() deletes a category previously added, and getCategories() gets the set of all categories currently in the object.

The Intent object has a series of put...() methods for inserting various types of extra data and a similar set of get...() methods for reading the data. These methods parallel those for Bundle objects. In fact, the extras can be installed and read as a Bundle using the putExtras() and getExtras() methods.

Only three aspects of an Intent object are consulted when the object is tested against an intent filter:
data (both URI and data type) 

Activities that are willing to receive implicit intents must include "android.intent.category.DEFAULT" in their intent filters ("android.intent.action.MAIN" and "android.intent.category.LAUNCHER" are exceptions to that rule, they don't need to include CATEGORY_DEFAULT).

Data specification for intent filter:
For example, in the following URI,
the scheme is "content", the host is "com.example.project", the port is "200", and the path is "folder/subfolder/etc".

The type attribute of a <data> element specifies the MIME type of the data. It's more common in filters than a URI. Both the Intent object and the filter can use a "*" wildcard for the subtype field — for example, "text/*" or "audio/*" — indicating any subtype matches.

I've gotta re-read the NotePad example to make sure I got it all right. It's a bit late, or should I say, it's already early - in the morning. Nite!

No comments:

Post a Comment