0% found this document useful (0 votes)
10 views23 pages

Module 2

Uploaded by

mthanuja44
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views23 pages

Module 2

Uploaded by

mthanuja44
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

SWE2008 ANDROID

PROGRAMMING
Module – 2
Android Application Basics
Anatomy of Android Application
• Context
• Activity
• Fragment
• Intent
• Service
Anatomy of Android Application

• The Application Context


• Retrieving application resources such as strings, graphics, and XML
files
• Accessing application preferences
• Managing private application files and directories
• Retrieving uncompiled application assets
• Accessing system services
• Managing a private application database
• Working with application permissions
Anatomy of Android Application
Anatomy of Android Application
• Managing Activity Transitions with Intents
• In the course of the lifetime of an Android application, the user might
transition between a number of different Activity instances

• At times, there might be multiple Activity instances on the Activity


stack. Developers need to pay attention to the lifecycle of each
Activity during these transitions

• Transitioning between Activities with Intents

• A specific Activity can be designated as the main Activity to launch by


default within the AndroidManifest.xml file
Anatomy of Android Application
Anatomy of Android Application
Organizing Application Navigation with Activities and Intents
• Main menu or list-style screen
• Drill-down-list-style screen
• Click actions
• Options menus
• Action-bar-style navigation
Anatomy of Android Application
• Working with Services
• Receiving and Broadcasting Intents
Application using the android manifest file
• Android manifest file to determine application settings such as the
application name and version, as well as what permissions the
application requires to run and what application components it is
composed of
• The Android application manifest file is a specially formatted XML file
that must accompany each Android application
• This file contains important information about the application’s identity
• Specify application system requirements, including which Android SDKs
are sup ported, what device configurations are required (for example,
D-pad navigation), and which platform features the application relies
upon (for example, multitouch capabilities)
• Specify what features are required by the application for market-
filtering purposes
Application using the android manifest file
• Register application activities and when they should be launched
• Configure other advanced application component configuration details,
including defining services, broadcast receivers, and content providers
• Specify intent filters for your activities, services, and broadcast receivers
• Enable application settings such as debugging and configuring
instrumentation for application testing
Editing the Android Manifest File
• Editing the Manifest File Using the Android IDE
• The Manifest tab
• The Application tab
• The Permissions tab
• The Instrumentation tab
• The AndroidManifest.xml tab
Managing Your Application’s Identity
Managing Application Resources

• All Android applications are composed of two things: functionality (code


instructions) and data (resources)
• The functionality is the code that determines how your application
behaves
• This includes any algorithms that make the application run. Resources
include text strings, styles and themes, dimensions, images and icons,
audio files, videos, and other data used by the application
Storing Application Resources
• Android resource files are stored separately from the .java class files in
the Android project
• Most common resource types are stored in XML
• Resources are organized in a strict directory hierarchy
Storing Application Resources
Resource Value Types

• Android applications rely on many different types of resources—such


as text strings, graphics, and color schemes—for user interface design

• These resources are stored in the /res directory of your Android


project in a strict (but reasonably flexible) set of directories and files.
All resource filenames must be lower case and simple (letters,
numbers, and underscores only)

• Storing Primitive Resource Types

• Simple resource value types, such as strings, colors, dimensions, and


other primitives, are stored under the /res/values project directory in
XML files
Managing Application Resources
Storing Graphics and Files
• In addition to simple resource types stored in the /res/values
directory, you can also store numerous other types of resources, such
as graphics, arbitrary XML files, and raw files
• These types of resources are not stored in the /res/values directory
but instead are stored in specially named directories according to
their type
• Make sure you name resource files appropriately because the
resource name for graphics and files is derived from the filename of
the specific resource
Storing Other Resource Types
• All other resource types with animation sequences, color state lists,
or menus are stored in special XML formats in various directories
• A simple application with its requisite string, graphics, and layout
resources.
• The resources are stored in the top-level resource directories (for
example, /res/values/strings.xml, /res/drawable/mylogo.png, and
/res/layout/main.xml)
• We could use alternative graphics resources to do this. For example,
we could provide different logos for different device screen densities
by providing five versions of mylogo.png
• /res/drawable-ldpi/mylogo.png (low-density screens)
• /res/drawable-mdpi/mylogo.png (medium-density screens)
• /res/drawable-hdpi/mylogo.png (high-density screens)
• /res/drawable-xhdpi/mylogo.png (extra-high-density screens)
• /res/drawable-xxhdpi/mylogo.png (extra-extra-high-density screens)
Managing Application Resources
Working with different types of resources
Working with String Resources

• String resources are among the simplest resource types available to


the developer. String resources might be used to show text labels on
form views and for help text. The application name is also stored as a
string resource, by default
Managing Application Resources
• Working with Boolean Resources
• Boolean resources can be used to store information about
application game preferences and default values

• Boolean values are appropriately tagged with the tag and represent a
name/value pair

• To use a Boolean resource in code, you can load it using the


getBoolean() method of the Resources class
Working with Integer Resources
• Integer resources are defined in XML under the /res/values project
directory and compiled into the application package at build time

• Integer values are appropriately tagged with the tag and represent a
name/ value pair

• To use the integer resource, you must load it using the Resources
class
Working with Colors
• Android applications can store RGB color values, which can then be
applied to other screen elements

• RGB color values always start with the hash symbol (#). The alpha
value can be given for transparency control. The following color
formats are supported

• #RGB (for example, #F00 is 12-bit color, red)

• #ARGB (for example, #8F00 is 12-bit color, red with alpha 50%)
• Working with Dimensions
• Drawable Resources
• Working with Images
• Working with Color State Lists
• Working with Animation
Working with layouts
• Much as Web designers use HTML, user interface designers can use XML
to define Android application screen elements and layout

• A layout XML resource is where many different resources come together


to form the definition of an Android application screen

• Layout files might include many user interface con trols and define the
layout for an entire screen or describe custom controls used in other
layouts

• Layout resource files are included in the /res/layout/ directory


Designing Layouts in the Android IDE
• Layouts can be designed and previewed in the Android IDE by using
the resource editor functionality

• If you click the project file /res/layout/activity_


simple_resource_view.xml, you see the Layout tab, which shows a
preview of the Graphical Layout, and the
activity_simple_resource_view.xml tab
Using Layout Resources Programmatically
• Objects within layouts, whether they are Button or Image View
controls, are all de rived from the View class
• Developers can also define custom layouts with unique attributes
Referencing System Resources
• Animation sequences for fading in and out
• Arrays of email/phone types (home, work, and such)
• Standard system colors
• Dimensions for many commonly used drawable and layout types
• Error strings and standard button text
• System styles and theme application thumbnails and icons

You might also like