22 Dec 2011

Core building blocks
the main components that Android provides for building application:

■ Activity—The foreground; they dictate the UI, and handle events and interaction

■ Service—The background; they can perform long-running tasks or poll

■ BroadcastReceiver—Handlers that can wake up and respond to broadcast events (intents)

■ ContentProvider—Allows you to expose a data API to other applications



■ Views—UI elements that are drawn onscreen
■ Layouts—View hierarchies that control screen format/appearance
■ Intents—Messages wiring components together
■ Resources—External elements, such as strings and drawables (pictures)
■ Manifest—Configuration for applications

RESERVED RESOURCE IDS Android uses predefined reserved IDs not only for lists, but also in some other places. One other example of this is TabActivity, which will look for the tabhost, tabcontent, and tabs IDs in your layout. You can also use them to access views defined in some of Android’s predefined layouts. For instance, Android ships with default layouts for list items, such as simple_list_item_1 and simple_list_item_2 for single- and two-line textbased list items.

ANONYMOUS INNER CLASSES You could define a class in a separate file that implements a listener interface when you need it, then create an instance of that class, and then use it for the adapter’s listener. Alternatively you could declare that the current class you’re working on implements the interface and you could include the required method locally (and if you have multiple listeners, you can use the same method and filter for the correct component within it). There are several approaches to dealing with this situation, and
which one to choose depends on the situation to some degree, and your personal preference. We find anonymous inner classes convenient and capable, and that’s why we’ve chosen them, although they aren’t easy to understand at first. One of the advantages of anonymous inner classes is that they have variable
scope access to the enclosing method and class variables through a feature known as lexical closure.



No comments: