Friday, September 14, 2012

Step By Step Learn Mobile Application Development Android




Step By Step Learn
Mobile Application Development Android

By: - Rakesh Kumar Jha
M. Tech. MCA
+91 8050753516


Introduction

Today is mobile eras basically as more and more people bring Mobile devices into their daily lives that connect them to the worldwide network in its countless forms. Every aspect of life inside mobile, education, entertainment, game, banking etc, due to in part to changes in current situation, competition, and job opportunity and global education and competition market structures.

Mobile devices are not only convenient and always with us, they are the focus of a convergence of capability, each device offering a combination of applications to support for daily life.

To learn mobile technologies it will give huge benefits to life, positive ROI on their learning, mobile learning is a transformative opportunity.. The tree of digital convergence has borne fruit, and it is only now that we are now picking the low-hanging, mobile learning being one of them.


Mobile devices are not only convenient and always with us, they are the focus of a convergence of capability, each device offering a combination of applications to support for daily life.
  • Documents
  • Audio
  • E-mail
  • IM, SMS, and MMS
  • Video
  • Interactive computer applications
  • The World Wide Web
  • Geolocation
  • Social interaction
Note – Think ! Mobile will do it J

Smartphone OS
Ø  Symbian
Ø  Windows Mobile
Ø  RIM Blackberry OS
Ø  Apple iOS
Ø  Google Android
Ø  Palm WebOS
Ø  Windows Phone 7
Several Mobile operating system is available, why Android? What is the feature of Android? How easy to learn Android? Main objective of this article and consecutive article is to learn Mobile application development through Android.

Agenda for this article:-

Ø  What is Android?
Ø  Why develop an Android apps
Ø  Feature of Android
Ø  Download Software
Ø  Architecture of Android
Ø  Fundamentals
Ø  Tools and Environment configuration for Android
Ø  Write your first program “Hello World”
Ø  Detail description of HelloWorld Program




 What is Android?

Android was created by Android, Inc.  A small startup company in Palo Alto, CA.  Acquired by Google in 2005 (prior to first iPhone release).
Android is a software stack for mobile devices that includes an operating system, middleware and key applications. The Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language *. Android is open source under the Apache license.

In 2007, the Open Handset Alliance unveiled their first product, Android, a mobile device platform built on Linux kernel 2.6. Key members included Google, HTC, Texas Instruments, Intel, Motorola, nVidia, Qualcomm, Samsung, Sprint, T-Mobile and Marvell Technology Group


Image 1.





What is the Open Handset Alliance (OHA)?

Group of companies from different area of specialization like, semiconductor, Mobile handset manufacturer, telecom expert.



 Image 2.







  • Why Develop an Android App
  • Few statics is given below for understand why we develop application in Android.
  • Android statistics in year 2011
  •  Android activations swelling to over 100 million worldwide (112 countries) on 215 carriers and 36 manufacturers
  • 310 different Android devices
  •  400,000 activations per day, compared to 100,000/day in May of 2010, 200,000/day in August and 300,000/day in December.
  •  200,000 Android applications are now available in the marketplace
  •  4.5 billion applications installed from Android Market





What we can do with Android?
  • Application framework enabling reuse and replacement of components
  • Dalvik virtual machine optimized for mobile devices
  • Integrated browser based on the open source webkit engine
  • Optimized graphics powered by a custom 2D graphics library; 3D graphics based on the OpenGL ES 1.0 specification (hardware acceleration optional)
  • SQLite for structured data storage
  • Media support for common audio, video, and still image formats (MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, GIF)
  • GSM Telephony (hardware dependent)
  • Bluetooth, EDGE, 3G, and WiFi (hardware dependent)
  • Camera, GPS, compass, and accelerometer (hardware dependent)
  • Rich development environment including a device emulator, tools for debugging, memory and performance profiling, and a plugin for the Eclipse IDE




Android Architecture Image - 





Fundamental of Android

Activity - An activity is a single, focused thing that the user can do. Almost all activities interact with the user, so the Activity class takes care of creating a window for you in which you can place your UI with setContentView(View)
Service - A Service is an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use.
ContentProvider - Content providers are one of the primary building blocks of Android applications, providing content, information data to applications.
Intent - An intent is an abstract description of an operation to be performed.
AndroidManifest.xml - The deployment descriptor for an application.
Application Resources - External to the source code and often in an XML file. Strings, images, screen layouts, menus, assets, etc...
Data Storage - SQLite database, SD card, internal storage (flash memory) and network storage.
Location and Maps - Location of handset, Geocoding and Google Maps API.

Underlying all applications is a set of services and systems, including:

  •    A rich and extensible set of Views that can be used to build an application, including lists, grids, text boxes, buttons, and even an embeddable web browser
  •   Content Providers that enable applications to access data from other applications (such as Contacts), or to share their own data
  •    A Resource Manager, providing access to non-code resources such as localized strings, graphics, and layout files
  •   A Notification Manager that enables all applications to display custom alerts in the status bar
  •   An Activity Manager that manages the lifecycle of applications and provides a common navigation


Android Runtime

  •      Android includes a set of core libraries that provides most of the functionality available in the core libraries of the Java programming language.
  •   Every Android application runs in its own process, sandbox, with its own instance of the Dalvik virtual machine.
  •    Dalvik has been written so that a device can run multiple VMs efficiently.
  •   The Dalvik VM executes files in the Dalvik Executable (.dex) format which is optimized for minimal memory footprint.
  •   The VM is register-based, and runs classes compiled by a Java language compiler that have been transformed into the .dex format by the included "dx" tool.
  •      The Dalvik VM relies on the Linux kernel for underlying functionality such as threading and low-level memory management.

  
 Tools and Environment configuration


 Android SDK
Ø  Platforms – Fully compliant android library and system image (production release)
Ø  Components – Add-ons like Google APIs
Ø  Virtual Devices – Creation of devices simulating specific handset hardware and platform for emulator behavior.

Integrated Development Environment
Ø  Eclipse – Version 3.4 or 3.5 to work with the
Ø  Android Development Tools (ADT) plugin.

Development requirements
         Java (J2SE)
         Android SDK
         Eclipse IDE (optional) 



 Installation & Configuration of Android on Eclipse







  1. Installing the SDK tools on a Windows machine
  2. Installing the SDK tools on a Mac
  3. Installing platforms and samples
  4. Creating an Android Virtual Device (emulator)
  5. Installing Eclipse on a Mac
  6. Installing Eclipse on a Windows machine
  7. Installing the Android Development Tools
  8. Preparing an Android device for development

Here I’ll show you how to install and configure Android in Eclipse over Windows machine


  1. Installing the SDK tools on a windows system
  2. Prepare your development computer
  3. Download  the SDK starter package
  4. Install the ADT plugin for eclipse.
  5. Add platform and other packages.
  6. Resources -
     1. Eclipse : http://www.eclipse.org/downloads/
     2. SDK: http://developer.android.com/sdk/index.html
     3. ADT: http://developer.android.com/sdk/eclipse-adt.html
     4. Java: http://www.java.com/en/download/index.jsp
Note -- 


Eclipse IDE

  • Eclipse 3.6.2 (Helios) or greater
    Note: Eclipse 3.5 (Galileo) is no longer supported with the latest version of ADT.
  • Eclipse JDT plugin (included in most Eclipse IDE packages)
  • JDK 6 (JRE alone is not sufficient)
  • Android Development Tools plugin (recommended)
  • Not compatible with Gnu Compiler for Java (gcj)


Installing ADT in Eclipse Image - 






Installing ADT Plugin
Ø  Help -> Install New Software -> Add -> Archive  -> write the name of ADT









Installing SDK Platform
Ø  Windows > Android Sdk Manager>select package you want to install. 




Installing SDK Image - 



After installation and configure, here will see how to create a simple HelloWorld Program in Android Image - 




Create new project in workspace





  1. Write project name
  2. Select create new project in workspace (if you wanted your won project)
  3. Click next
  4. select version over you wanted to run you application
  5. click next
  6. change the package name to meaning full like “com.kt.hello” or “com.kt.helloworld” or “com.sdj.helloworld”
  7. click finish
  8. Now your hello world project is created.
  9. Create AVD (Android Virtual Device)
    1. You will have to create an AVD for testing your android applications. An AVD is an emulator instance
    2. that enables you to model an actual device.
    3. To create an AVD: Windows > AVD Manager > New
      1.  write emulator Name
      2.   Set target


Images - 

















      For each level, two platforms are available. For example, level 8 offers the following:
      SDK Platform Android 2.2
      Google APIs by Google Inc.

The key difference between the two is that Google APIs contains the Google Maps API that is required if your application makes use of Google Maps



Next description of project structure and each and every files.


Image 





Project creation
1. Create a new Project. File > Project > Android > Android Project.
2. Name the project – HelloWorld,
    Package Name: com.kt.helloworld,
    Applicationname: HelloWorld,
    Create Activity: HelloWorldActivity
    Finish


Project Structure
    After you create a new project in eclipse, you will see the following top-level folders in your package explorer.
  1. /src
  2. /gen
  3. /Android version
  4. /assets
  5. /bin
  6. /res
    1. /drawable
    2. /Layout
      1. main.xml
    3. /Values
      1. Strings.xml
  7. Androidmanifest.xml

SRC

The structure of an Android Application

      src –
      Contains the .java source files for your project.

      HelloWorldActivity.java.
      This file is the source file for your activity.

      Android 2.2 Library –
      This item contains one file, android.jar, which contains all the class librariesneeded for an Android application.

      gen –
       Contains the R.java file, a compiler-generated file that references all the resources found in your
      Android Project. You should not modify this file. As you add the files & folders in your application,
      Eclipse will automatically generate the content of R.java.

      assets –
      This folder contains all the assets used by your application, such as HTML, text files,databases, etc.

      res –
      This folder contains all the resources used in your application. It also contains a few

  sub-folders:

      drawable-<resolution>, layout, values.

      AndroidManifest.xml –
      This is the manifest file for your application.
      Here you specify the permissions needed by your application, as well as other features (such as intent-filters, receivers, etc.)

      strings.xml
       Located in the res > values folder, is a file for storing all the string constants and reference the string using the @string identifier.
      This will ease your task of localizing your application to another language, all you need to do is replacing the string values from the local applications and recompile your application.

      AndroidManifes.xml
      Every application must have the AndroidManifest.xml in its root directory.
       It provides essential information about the application to the Android system,  information the system must have before it can run any of the application's code.
      These information are
      Java package
      Components of the application
      Identify any user permissions the application requires, such as Internet access or read-access to the user's contacts.
      Declare the minimum API level required by the application, based on which APIs the application uses.
      Declare hardware and software features used or required by the application, such as a camera, bluetooth services, or a multitouch screen.
      API libraries the application needs to be linked against (other than the Android framework APIs), such as the Google Maps library.









Activity class details
//Package name
package com.kt.helloworld;

//all import package
import android.app.Activity;
import android.os.Bundle;

//class name with extends (super class) Activity
public class HelloWorldActivity extends Activity {

    /** Called when the activity is first created.*/
//Oncreate method will called first time when HelloWorldActivity class //called first

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

// Call/bind UI (main.xml) file to Activity class i.e. //HelloWorldActivity
 
        setContentView(R.layout.main);
    }
}


AndroidManifest.class details

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.kt.helloworld"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="14" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".HelloWorldActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>



main.xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="@string/hello" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="2sp"
        android:background="#ff0000" />
<View
        android:layout_width="fill_parent"
        android:layout_height="5sp"/>
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Welcome to Rakesh Jha Android Training Class />

    <View
        android:layout_width="fill_parent"
        android:layout_height="2sp" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="www.android-expert.blogspot.com" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Email – rkjhaw@hotmail.com" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="2sp" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Welcome to Rakesh Jha Android Training Class " />

</LinearLayout>

Once you run above code, below screen will come as output.





Images -









In next series will see basic component of Android and Life cycle of Android
Basically each and every components like, Java file, services and broadcast receiver will linked through the manifest file –

Images






5. Conclusion
To understand, why Android is easy to learn. Android setup and configuration

6. Author's bio
Rakesh Kumar Jha, M. Tech. having 6+ yrs of  in Web and Mobile Programming.
6. References
http://www.openhandsetalliance.com
http://developer.android.com/index.html
http://stackoverflow.com/questions/tagged/android
http://groups.google.com/group/android-developers
http://groups.google.com/group/android-discuss
http://www.google.com/support/forum/p/Android+Market
http://www.anddev.org/
http://code.google.com/events/io/2010/sessions.html#Android