android tutorial

Android Tutorial for Beginners : Learn Android Programming Online

Android is a mobile operating system. The goal of this Android tutorial give newcomers a thorough understanding of Android’s fundamentals, features, and some of the important subjects.

If you must have at least a fundamental understanding of Java programming if you are interested in developing applications for Android. Android programming is done with Java syntax and a class library that resembles a portion of the Java SE library (with Android-specific enhancements). Before attempting to plunge into programming for Android, you should probably quickly learn how Java works if you have never done it before.

Android Tutorial

What is Android?

A customized version of Linux serves as the foundation for the mobile operating system known as Android. Android, Inc., a start-up with the same name, created it in the beginning. Google bought Android and took over its development work (as well as its development team) in 2005 as part of their strategy to enter the mobile space. Since Google wanted Android to be open and free, the majority of the code was made available under the Apache License, which is an open-source agreement. As a result, anyone who wants to use Android can do so by downloading the complete Android source code. Vendors can also alter Android and add their own proprietary extensions to it to set their goods apart from competing ones (usually hardware makers).

Android is particularly appealing because to its straightforward development architecture, which has attracted the attention of numerous suppliers. This has been particularly true for businesses impacted by the iPhone phenomenon—an enormously popular product that completely changed the smartphone market. These businesses, like Motorola and Sony Ericsson, have been creating their own mobile operating systems for many years. Many of these manufacturers were forced to scurry to come up with fresh ideas for reviving their goods when the iPhone was introduced.

These manufacturers view Android as the answer, and they will keep creating their own hardware with Android as the operating system. Adopting Android offers a unified approach to application development, which is its fundamental benefit. As long as the devices are powered by Android, developers just need to create applications for Android, and those applications should be able to operate on a variety of different devices. The most crucial link in the success chain for cellphones is the application. Therefore, device makers view Android as their greatest chance to compete with the iPhone, which already commands a sizable pool of applications.

Android Versions

Android has gone through quite a number of updates since its first release. Below table shows the various versions of Android and their codenames.

Features of Android

As Android is open source and freely available to manufacturers for customization, there are no fixed hardware and software configurations.

However, Android itself supports the following features:

  • Storage — Uses SQLite, a lightweight relational database, for data storage. Chapter 6 discusses data storage in more detail.
  • Connectivity — Supports GSM/EDGE, IDEN, CDMA, EV-DO, UMTS, Bluetooth (includes A2DP and AVRCP), WiFi, LTE, and WiMAX. Chapter 8 discusses networking in more detail.
  • Messaging — Supports both SMS and MMS. Chapter 8 discusses messaging in more detail.
  • Web browser — Based on the open-source WebKit, together with Chrome’s V8 JavaScript engine
  • Media support — Includes support for the following media: H.263, H.264 (in 3GP or MP4 container), MPEG-4 SP, AMR, AMR-WB (in 3GP container), AAC, HE-AAC (in MP4 or 3GP container), MP3, MIDI, Ogg Vorbis, WAV, JPEG, PNG, GIF, and BMP
  • Hardware support — Accelerometer Sensor, Camera, Digital Compass, Proximity Sensor, and GPS Multi
  • Multi-touch — Supports multi-touch screens Multi
  • Multi-tasking — Supports multi-tasking applications
  • Flash support — Android 2.3 supports Flash 10.1.
  • Tethering — Supports sharing of Internet connections as a wired/wireless hotspot

Android Tutorial :Architecture

In order to understand how Android works, take a look at Figure 1-1, which shows the various layers that make up the Android operating system (OS). The Android OS is roughly divided into five sections in four main layers:


Linux kernel –The kernel on which Android is built is this. All of the low level device drivers for the various hardware parts of an Android device are present in this layer.

Libraries — These contain every piece of code responsible for an Android OS’s core functions. For instance, the SQLite library offers support for databases so that an application can use them to store data. The WebKit library offers features for viewing the web.

Android runtime — The Android runtime offers a set of core libraries at the same layer as the libraries, allowing programmers to create Android apps using the Java programming language. Every Android application can operate in its own process with its own instance of the Dalvik virtual machine thanks to the Dalvik virtual machine, which is a component of the Android runtime (android applications are built into the Dalvik executables). Dalvik is a unique virtual machine created especially for Android that is suited for mobile devices with little RAM and CPU power.

Application framework — Exposes the various capabilities of the Android OS to application developers so that they can make use of them in their applications.

Applications — This top layer contains both programs that you download and install from the Android Market as well as applications that come pre-installed on the Android device (such as Phone, Contacts, Browser, etc.). You can write any applications you want at this layer.

To Create New Android Project – Android Tutorial

The Android build system is organized around a specific directory tree structure for your Android project, much like any other Java project. The specifics, though, are fairly unique to Android and what it all does to prepare the actual application that will run on the device or emulator. Here’s a quick primer on the project structure, to help you make sense of it all, particularly for the sample code. 

Root Contents

When you create a new Android project (e.g., via activityCreator.py), you et five key items in the project’s root directory:

  • AndroidManifest.xml, which is an XML file describing the application being built and what components – activities, services, etc. – are being supplied by that application
  • build.xml, which is an Ant script for compiling the application and installing it on the device
  • bin/, which holds the application once it is compiled
  • src/, which holds the Java source code for the application
  • res/, which holds “resources”, such as icons, GUI layouts, and the like, that get packaged with the compiled Java in the application
  • assets/, which hold other static files you wish packaged with the application for deployment onto the device

The fully-qualified class name of the “main” activity for the application was supplied when the project was established (for example, using activityCreator.py), example, com.commonsware.android.SomeDemo.  The namespace directory tree and a stub Activity subclass representing your primary activity (for example, src/com/commonsware/android/SomeDemo.java) will then be present in your project’s src/ tree. To implement your application, you are free to change this file and add additional ones to the src/ tree.

The first time you compile the project (e.g., via ant), out in the “main” activity’s namespace directory, the Android build chain will create R.java. This contains a number of constants tied to the various resources you placed out in the res/ directory tree.

Android Permissions

  • uses-permission elements, to indicate what permissions your application will need in order to function properly
  • permission elements, to declare permissions that activities or services might require other applications hold in order to use your application’s data or logic – again,

Android Instrumentations

  • Android instrumentation elements, to indicate code that should be invoked on key system events, such as starting up activities, for the purposes of logging or monitoring

Andnroid Applications

an application element, defining the guts of the application that the manifest describes.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.commonsware.android">
<uses-permission
android:name="android.permission.ACCESS_LOCATION" />
<uses-permission
android:name="android.permission.ACCESS_GPS" />
<uses-permission
android:name="android.permission.ACCESS_ASSISTED_GPS" />
<uses-permission
android:name="android.permission.ACCESS_CELL_ID" />
<application>
...
</application>
</manifest>

In the preceding example, the manifest has uses-permission elements to indicate some device capabilities the application will need – in this case, permissions to allow the application to determine its current location. And, there is the application element, whose contents will describe the activities, services, and whatnot that make up the bulk of the application itself.

The real meat of the manifest file are the children of the application element. By default, when you create a new Android project, you get a single activity element:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.commonsware.android.skeleton">
<application>
<activity android:name=".Now" android:label="Now">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

This element provides android:name for the class that is responsible for the activity’s implementation, android:label for the activity’s display name, and (often) an intent-filter child element outlining the circumstances under which this activity would be displayed. The stock activity element configures your activity so that it may be launched by users by making it visible in the launcher.

Android Tutorial for beginners explain what Android, and it gives a brief understanding of messaging and important Android concepts are explained above post. I will be adding more posts in Android tutorial, so please bookmark the post for future reference too.