Android Programming - Lecture 3
Android Programming - Lecture 3
IT (V-Sem)
Course Code: BCI-543
Course Credit: 3
Android Programming
By
Mr. Honey Gocher
PhD. Scholar (Software Engineering)
Amity University Jaipur, Rajasthan
Android Building Blocks
• An android component is simply a piece of code that has a well defined life
cycle e.g. Activity, Receiver, Service etc.
• The core building blocks or fundamental components of android are:
1. Activities
2. Views
3. Intents
4. Services
5. Content providers
6. Fragments
7. AndroidManifest.xml.
Android Fundamentals
Android Building Blocks
• Activity
• An activity is a class that represents a single screen. It is like a Frame in AWT.
• View
• A view is the UI element such as button, label, text field etc. Anything that you
see is a view.
• Intent
• Intent is used to invoke components. It is mainly used to:
• Start the service
• Launch an activity
• Display a web page
• Display a list of contacts
• Broadcast a message
• Dial a phone call etc.
Android Building Blocks
• Service
• Service is a background process that can run for a long time.
• There are two types of services local and remote. Local service is accessed from
within the application whereas remote service is accessed remotely from other
applications running on the same device.
• Content Provider
• Content Providers are used to share data between the applications.
• Fragment
• Fragments are like parts of activity. An activity can display one or more
fragments on the screen at the same time.
• Android Manifest.xml
• It contains informations about activities, content providers, permissions etc.
Android Building Blocks
• Activities
• It Control the UI and handle the user interaction to the Android App screen, it
represents a single screen with a user interface. Activity performs actions on
the screen, For example, Medium application might have one activity that
shows a list of articles while another activity to read the Notifications and
another activity for viewing user profile.
• Services
• The Service is another building block of Android applications. They handle
background running tasks associated with an application. It is a program that
can run in the background for an infinite period and it does not provide a UI. A
good example of service is the music player app, let us consider Google play
Music which keep on playing music while the main android app activity is
destroyed or closed.
Android Building Blocks
• Broadcast Receivers
• They handle communication between core Android OS and applications
running on the surface layer. The application modules communicate with each
other using the broadcast receiver. Messages can be initiated by the system or
the app. For example, if a user is using your app and a phone call comes in,
the Broadcast Receiver interface will notify your app.
• Content Providers
• They handle data interchange and database related components. This provides
a uniform singular interface to the content & data. The content can be from
your app being exposed to the system or other apps or it could be system
content for example, pictures on your phone, contact lists, or files in the file
system. It provides a consistent interface to retrieve/store data via external
data sources or databases.
UI Components
• Android UI Controls are those components of Android that are used to
design the UI in a more interactive way. It helps us to develop an
application that makes user interaction better with the view
components. Android provides us a huge range of UI controls of many
types such as buttons, text views, etc. Top UI controls are:
• TextView
• EditText
• Button
• ImageButton
• ToggleButton
• RadioButton
• RadioGroup
UI Components
• CheckBox
• AutoCompleteTextView
• ProgressBar
• Spinner
• TimePicker
• DatePicker
• SeekBar
• AlertDialog
• Switch
• RatingBar
Intent in Android Programming
• An intent is to perform an action on the screen. It is mostly used to start activity,
send broadcast receiver, start services and send message between two activities.
There are two intents available in android as Implicit Intents and Explicit Intents.
• An Activity represents a single screen in an app. You can start a new instance of
an Activity by passing an Intent to startActivity(). The Intent describes the activity
to start and carries any necessary data.
• An Intent object carries information that the Android system uses to determine
which component to start (such as the exact component name or component
category that should receive the intent), plus information that the recipient
component uses in order to properly perform the action (such as the action to take
and the data to act upon).
Intent Types
• There are two types of intents:
• Explicit intents: specify which application will satisfy the intent, by supplying either the
target app's package name or a fully-qualified component class name. You'll typically use an
explicit intent to start a component in your own app, because you know the class name of
the activity or service you want to start. For example, you might start a new activity within
your app in response to a user action or start a service to download a file in the background.
• Implicit intents: do not name a specific component, but instead declare a general action to
perform, which allows a component from another app to handle it. For example, if you want
to show the user a location on a map, you can use an implicit intent to request that another
capable app show a specified location on a map.
Information in Intent
• Component Name: The name of the component to start.
• Action: A string that specifies the generic action to perform (such as view or pick).
• Data: The type of data supplied is generally dictated by the intent's action. For example,
if the action is ACTION_EDIT, the data should contain the URI of the document to edit.
• Category: A string containing additional information about the kind of component that
should handle the intent. Any number of category descriptions can be placed in an intent,
but most intents do not require a category
• Extras: Key-value pairs that carry additional information required to accomplish the
requested action
• Flags:Flags are defined in the Intent class that function as metadata for the intent. The
flags may instruct the Android system how to launch an activity (for example, which task
the activity should belong to) and how to treat it after it's launched
Android API Levels
• API Level is an integer value that uniquely identifies the framework API
revision offered by a version of the Android platform.
• The Android platform provides a framework API that applications can use to interact
with the underlying Android system. The framework API consists of:
• A core set of packages and classes
• A set of XML elements and attributes for declaring a manifest file
• A set of XML elements and attributes for declaring and accessing resources
• A set of Intents
• A set of permissions that applications can request, as well as permission
enforcements included in the system
Android API Levels