Introduction to Android and Java
History :
Android is a software stack for mobile devices that includes an operating system, middleware and key applications.
Android's mobile operating system is based on a modified version of the Linux kernel. Google and other members of the Open Handset Alliance collaborated on Android's development and release.
Android, Inc. was founded in Palo Alto, California, United States in October, 2003 by Andy Rubin (co-founder of Danger),Rich Miner (co-founder of Wildfire Communications, Inc.), Nick Sears (once VP at T-Mobile),and Chris White (headed design and interface development at WebTV).
Types of Android Applications
Most of the applications you create in Android will fall into one of the following categories:
· Foreground An application that’s useful only when it’s in the foreground and is effectively suspended when it’s not visible. Games and map mashups are common examples.
· Background An application with limited interaction that, apart from when being configured, spends most of its lifetime hidden. Examples include call screening applications and SMS auto-responders.
· Intermittent Expects some interactivity but does most of its work in the background. Often these applications will be set up and then run silently, notifying users when appropriate. A common example would be a media player.
· Widget Some applications are represented only as a home-screen widget.
The Android Virtual Device and SDK Manager
The Virtual Device and SDK Manager is a tool used to create and manage the virtual devices that will host instances of your emulator. You can use the same tool both to see which version of the SDK you have installed and to install new SDKs when they are released.
Android Virtual Devices
Android Virtual Devices are used to simulate the software builds and hardware specifications available on different devices. This lets you test your application on a variety of hardware platforms without needing to buy a variety of phones.
Each virtual device is configured with a name, a target build of Android (based on the SDK version it supports), an SD Card capacity, and screen resolution, as shown in the ‘‘Create new AVD’’ dialog in Figure.
Each virtual device also supports a number of specific hardware settings and restrictions that can be added in the form of NVPs in the hardware table. These additional settings include:
Maximum virtual machine heap size
Screen pixel density
SD Card support
The existence of DPad, touchscreen, keyboard, and trackball hardware
GPS support
Available device memory
Camera hardware (and resolution)
Support for audio recording
Different hardware settings and screen resolutions will present alternative user-interface skins to represent the different hardware configurations. This simulates a variety of mobile device types. To complete the illusion, you can create a custom skin for each virtual device to make it look like the device it is emulating.
Android Development Tools
The Android SDK includes several tools and utilities to help you create, test, and debug your projects.
❑ The Android Emulator : The Android SDK includes a virtual mobile device emulator that runs on your computer. The emulator lets you prototype, develop, and test Android applications without using a physical device.
The Android emulator mimics all of the hardware and software features of a typical mobile device, except that it cannot place actual phone calls. It provides a variety of navigation and control keys, which you can "press" using your mouse or keyboard to generate events for your application. It also provides a screen in which your application is displayed, together with any other Android applications running.
Dalvik Debug Monitoring Service (DDMS)
Use the DDMS perspective to monitor and control the Dalvik virtual machines on which you’re debugging your applications.
Android ships with a debugging tool called the Dalvik Debug Monitor Server (DDMS), which provides port-forwarding services, screen capture on the device, thread and heap information on the device, logcat, process, and radio state information, incoming call and SMS spoofing, location data spoofing, and more.
Android Asset Packaging Tool (AAPT) Constructs the distributable Android package files (.apk).
The following diagram depicts the components involved in building and running an application:
A Detailed Look at the Build Process
The build process involves many tools and processes that generate intermediate files on the way to producing an.apk
. If you are developing in Eclipse, the complete build process is automatically done periodically as you develop and save your code changes. If you are using other IDEs, this build process is done every time you run the generated Ant build script for your project. It is useful, however, to understand what is happening under the hood since much of the tools and processes are masked from you. The following diagram depicts the different tools and processes that are involved in a build:- The Android Asset Packaging Tool (aapt) takes your application resource files, such as the
AndroidManifest.xml
file and the XML files for your Activities, and compiles them. AnR.java
is also produced so you can reference your resources from your Java code. - The aidl tool converts any
.aidl
interfaces that you have into Java interfaces. - All of your Java code, including the
R.java
and.aidl
files, are compiled by the Java compiler and .class files are output. - The dex tool converts the .class files to Dalvik byte code. Any 3rd party libraries and .class files that you have included in your project are also converted into
.dex
files so that they can be packaged into the final.apk
file. - All non-compiled resources (such as images), compiled resources, and the .dex files are sent to the apkbuilder tool to be packaged into an
.apk
file. - Once the
.apk
is built, it must be signed with either a debug or release key before it can be installed to a device. - Finally, if the application is being signed in release mode, you must align the
.apk
with the zipalign tool. Aligning the final.apk
decreases memory usage when the application is running on a device.
Android Debug Bridge (ADB) The ADB is a client-server application that provides a link to a running emulator. It lets you copy files, install compiled application packages (.apk), and run shell commands.
The following additional tools are also available:
- SQLite3 : A database tool that you can use to access the SQLite database files created and used by Android
- Traceview : Graphical analysis tool for viewing the trace logs from your Android application
- MkSDCard : Creates an SDCard disk image that can be used by the emulator to simulate an external storage card.
- dx Converts Java .class bytecode into Android .dex bytecode.
- activityCreator : Script that builds Ant build files that you can then use to compile your Android applications without the ADT plug-in
Android Architecture and OOPS
WHAT MAKES AN ANDROID APPLICATION?(Building block of android)
There are six components that provide the building blocks for your applications
View:
The concept of a view in J2EE and Swing carries over to Android. Views are UI elements that form the basic building blocks of a user interface. Views are hierarchical and they know how to draw themselves.
Activities:
Your application’s presentation layer. An activity is a user interface concept. An activity usually represents a single screen in your application. It generally contains one or more views, but it doesn’t have to.
Services:
Services in Android resemble services you see in Windows or other platforms—they’re background processes that can potentially run for a long time.
Android defines two types of services: local services and remote services.
· Local services are components that are only accessible by the application that is hosting the service.
· Remote services are services that are meant to be accessed remotely by other applications running on the device.
Content Provider:
Data sharing among mobile applications on a device is common. Therefore, Android defines a standard mechanism for applications to share data (such as a list of contacts, manage and share application databases). Through content providers, you can expose your data and have your applications use data from other applications.
Intent:
Intent generically defines an “intention” to do some work. You can use intents to perform the following tasks, for instance:
Broadcast a message
Start a service
Launch an activity
Display a web page or a list of contacts
Dial a phone number or answer a phone call
Intents are not always initiated by your application—they’re also used by the system to notify your application of specific events.