Application Building Blocks & Components Android applications are composed of one or more application components - Activity - Services - Intents - Content Providers - Broadcast Receivers Dept. of Computer Science and Engineering
May 25, 2015
Dept. of Computer Science and Engineering
Application Building Blocks & Components
Android applications are composed of one or more application components
- Activity - Services - Intents - Content Providers - Broadcast Receivers
Dept. of Computer Science and Engineering
Activity
• An activity corresponds to a screen. If an application is composed of several screens, it has an activity for each screen.
• Each activity is a class that extends the base class called Activity. It has a graphical user interface made of views, and it responds to events. When you change screen, a new activity is launched and It can return a value
• The graphical interface of an activity is described by a Layout
Dept. of Computer Science and Engineering
For example,
An email application might have one activity that shows a list of new emails, another activity to compose an email, and another activity for reading emails.
Dept. of Computer Science and Engineering
Application
• Create an application which calls one Activity into another
Dept. of Computer Science and Engineering
Intent
• Intents are verbs for android devices, which defines actions and are made effective by a new screen
E.g. CALL, SEND_MESSAGE.
• An intent is made up of an action and data that are URI.
• Components of an application — activities, services, and broadcast receivers , are activated through messages, called intents.
• In each case, the Android system finds the appropriate activity, service, or set of broadcast receivers to respond to the intent, instantiating them if necessary.
Dept. of Computer Science and Engineering
• Examples of actions: MAIN, VIEW, EDIT, PICK.
If one wants to see a card about a person, an intent is defined. The action is VIEW and the data is the URI which enables access to this card.
<intent-filter> <action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.EDIT" /> <action android:name="android.intent.action.PICK" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
</intent-filter>
Dept. of Computer Science and Engineering
IntentFilters
• Describes how the action should apply.• To inform the system which implicit intents they can handle activities,
services, and broadcast receivers
IntentReceiver
• It is an object that responds to external events. It can operate in the application or it can start an application.
• Example of intent, view a webpage: VIEW for action and for data http://www.linkToStuff.org.
Dept. of Computer Science and Engineering
Content Provider
• Data stored by a program, in the form of files or SQLite databases are private and may not be used by other applications.
• That is to say, a SQLite database created on Android by one application is usable only by that application, not by other applications. Databases created in Android are visible only to the application that created them
• So, if you need to share data between applications, you need to use the content provider.
Dept. of Computer Science and Engineering
For example,
• The Android system provides a content provider that manages the user's contact information. As such, any application with the proper permissions can query part of the content provider to read and write information about a particular person.
• Content providers are also useful for reading and writing data that is private to your application and not shared. For example, the Note Pad sample application uses a content provider to save notes.
Dept. of Computer Science and Engineering
To query a content provider, you provide a query string in the form of a URI, with an optional specifier for a particular row, using the following syntax:
<standard_prefix>://<authority>/<data_path>/<id>
Similarly, to retrieve all the contacts stored by the Contacts application, the URI would look like this:
content://contacts/people
Dept. of Computer Science and Engineering
Broadcast receivers
• A broadcast receiver is a component that responds to system-wide broadcast announcements.
• Many broadcasts originate from the system—for example, a broadcast announcing that the screen has turned off, the battery is low, or a picture was captured.
• Applications can also initiate broadcasts—for example, to let other applications know that some data has been downloaded to the device and is available for them to use.
• Although broadcast receivers don't display a user interface, they may create a status bar notification to alert the user when a broadcast event occurs.
Dept. of Computer Science and Engineering
Services
• A service is a component that runs in the background to perform long-running operations . It’s a faceless component of a process.
• A service does not provide a user interface.
• A service is designed to operate independently of the screen, can update your data source and activities, and trigger specific notations.
• The best example is the music player that can work in background and when we can be in some other activity.
Dept. of Computer Science and Engineering
Layouts
Dept. of Computer Science and Engineering
Types of Layout
• Absolute Layout• Frame Layout• Linear Layout• Relative Layout• Table Layout
Dept. of Computer Science and Engineering
AbsoluteLayout• For each view you add,
you specify the exact screen coordinate to display on the screen
Dept. of Computer Science and Engineering
Frame Layout• designed to display a
single item at a time.• element will be
positioned based on the top left of the screen
Dept. of Computer Science and Engineering
Linear Layout• organizes elements along a single line.• Can specify whether that line is vertical or
horizontal using android:orientation.
android:orientation changed to horizontal.
Dept. of Computer Science and Engineering
Relative Layout• lays out elements
based on their relationships with one another, and with the parent container.
Dept. of Computer Science and Engineering
Table Layout• Organizes content into
rows and columns.
Dept. of Computer Science and Engineering
Tea Break
Come back at 4:00