Android development overview

Source: Internet
Author: User
Tags sqlite database home screen

Http://www.ibm.com/developerworks/cn/opensource/os-android-devel/

Both BlackBerry and iPhone provide popular and high-capacity mobile platforms, but they target two different consumer groups respectively. Blackberry is the best choice for enterprise business users. However, as a consumer device, it is difficult to compete with the iPhone in terms of ease of use and novelty. Android is a young platform to be developed. It has the potential to cover two different consumer groups of mobile phones at the same time, and may even narrow the gap between work and entertainment.

Nowadays, many network-based or network-supported devices run some Linux kernel. This is a reliable platform: it provides cost-effective deployment and support, and can be directly used as a good deployment-oriented design method. The UI of these devices is generally HTML-based and can be viewed in a PC or Mac browser. However, not every device needs to be controlled by a conventional computing device. Imagine traditional household appliances, such as electric stove, microwave oven, or toaster. What if your household appliances are controlled by Android and have a color touch screen? If the electric stove has an android UI, the controller can even cook something.

In this article, we will learn about the Android platform and how to use it for mobile and non-mobile applications. Install the android SDK and build a simple application. Download the source code of the sample application in this article.

Back to Top

A Brief History of Android

The Android platform is the result of the Open Handset Alliance. The Open Handset Alliance organization is composed of a group of companies working together to build better mobile phones. The organization is led by Google, including mobile operators, handheld device manufacturers, component manufacturers, software solutions and platform providers, and marketing companies. From the perspective of software development, Android is at the center of the Open Source Field.

The first Android-supported mobile phone in the market is G1 made by HTC and supplied by T-Mobile. It took about a year from the idea to the launch of this device. The only available software development tool is some sdks that implement incremental improvements. As the G1 release day approaches, the android team released SDK V1.0, and applications used for the new platform also surfaced.

To encourage innovation, Google held two sessions of "android developer challenges" to reward millions of dollars for winning entries. A few months after G1 was launched, the Android Market was released, allowing users to browse applications and download them directly to their mobile phones. After about 18 months, a new mobile platform entered the public domain.

Back to Top

Android platform

Android has rich functions, so it is easy to confuse with the desktop operating system. Android is a hierarchical environment built on the basis of the Linux kernel, which includes rich functions. The UI subsystem includes:

  • Window
  • View
  • Widgets used to display common components (such as edit box, list, and drop-down list)

Android includes a WebKit-based embedded browser, and iPhone mobile safari is also based on WebKit.

Android provides a variety of connection options, including WiFi, Bluetooth, and wireless data transmission through cellular (cellular) connections (such as GPRS, edge, and 3G ). A popular technology in Android apps is linking to Google Maps to display addresses in apps. The Android software stack also provides support for location-based services (such as GPS) and accelerometer, but not all Android devices are equipped with necessary hardware. Camera support is also available.

In the past, mobile applications tried to align themselves with desktop applications in two areas: graphics/media and data storage methods. Android solves the graphics challenge by providing built-in support for 2D and 3D graphics, including OpenGL libraries. Because the Android platform includes the popular open source SQLite database, it relieves the burden on data storage. Figure 1 shows a simplified Android software hierarchy.

Figure 1. Android software hierarchy

Back to Top

Application Architecture

As mentioned above, Android runs on the Linux kernel. Android applications are programmed in Java and run in a Virtual Machine (VM. It should be noted that this VM is not the JVM you think, but Dalvik virtual machine, which is an open source technology. Each Android Application runs in an instance of Dalvik VM. This instance resides in a process managed by the Linux kernel, as shown in.

Figure 2. Dalvik VM

An android application consists of one or more components:

Activity
Applications with visual UI are implemented by activities. When you select an application from the home screen or application initiator, an action is triggered.
Service
The service should be used for any application that requires a long period of time, such as a network monitor or an Update Check application.
Content Providers
Content providers can be viewed as database servers. The task of the content provider is to manage access to persistent data, such as the SQLite database. If the application is very simple, you may not need to create a content provider. If you want to build a large application or an application that needs to provide data for multiple activities or applications, you can use the content provider for data access.
Broadcast Receiver
Android applications can be used to process a data element or respond to an event (such as receiving text messages.

Android applications are deployed to devices together with an androidmanifest. xml file. Androidmanifest. xml contains the necessary configuration information to install it to the device as appropriate. It includes the required class name and the type of event that the application can process, and the license required to run the application. For example, if the application needs to access the network-for example, to download a file-the manifest file must explicitly list the license. Many applications may have enabled this specific license. This declarative Security helps reduce the possibility that malicious applications may damage devices.

The next section describes the development environment required to build an Android Application.

Back to Top

Required tools

The simplest way to start developing Android applications is to download the android SDK and Eclipse IDE (see references ). Android development can be performed on Microsoft Windows, Mac OS X, or Linux.

This document assumes that you are using Eclipse IDE and the android Developer Tools plug-in for eclipse. Android applications are compiled and executed in Java, but are compiled and executed in Dalvik VM (non-Java Virtual Machine. Programming With the Java language in eclipse is very simple. Eclipse provides a rich Java environment, including context-sensitive help and code prompts. After the Java code is compiled, Android Developer Tools can ensure that it is packaged properly, including the androidmanifest. xml file.

Although Android applications can be developed without the eclipse and Android Developer Tools plug-ins, you need to be familiar with the android SDK.

Android SDK is released as a zip file. You can decompress the file to a directory on the hard disk. Since there are multiple SDK updates, we recommend that you consciously organize the development environment so that you can easily switch between different SDK installations. The SDK includes:

Android. Jar
Java archive file, which contains all the android SDK classes required to build the application.
Ention.html and docs Directories
Local and online SDK documentation. These documents are mainly in the form of javadocs to facilitate the navigation of a large number of packages in the SDK. The document also includes a link to the Advanced Development Guide and the android community.
Samples Directory
The samples subdirectory contains the source code of various applications, including apidemo, which demonstrates many APIs. This sample application can be used as a good starting point for Android application development.
Tools directory
Contains all command line tools used to build Android applications. The most common and useful tool is adbUtility (Android debug Bridge ).
Usb_driver
This directory contains the drivers required to connect the development environment to devices that support Android (such as G1 or android Dev 1. Only Windows developers need these files.

The Android Application can run on the actual device or the android emulator attached to the android SDK. Figure 3 shows the main screen of Android emulator.

Figure 3. Android emulator

Android debug Bridge

adbThe utility supports some optional command line parameters to provide powerful features, such as copying a file to a device or copying a file from a device. You can use shell command line parameters to connect to the mobile phone itself and send basic shell commands. Figure 4 showsadbShell Command.

Figure 4. UseadbShell commands

In this shell environment, you can:

  • The network configuration is displayed. The network configuration displays multiple network connections. Note the following Network Connections:

    • loIs a local or loopback connection.
    • tiwlan0Is a Wi-Fi connection, which is provided by the local DHCP server.
  • DisplayPATHEnvironment variable content.
  • RunsuCommand to become a Super User.
  • Change the directory to/data/APP, where the user application is stored.
  • Lists the directories that contain an application. Android Application Files are actually archive files, which can be viewed through software such as WinZip. The extension is APK.
  • Run the ping command to check whether Google.com is available.

In the same command prompt environment, you can also interact with the SQLite database, start programs, and execute many other system-level tasks. Imagine that you are connecting to the phone, so this is a great feature.

In the next section, you will create a simple Android Application.

Back to Top

Write a basic application

This section describes how to build an Android Application. The sample application is very simple: a modified "Hello android" application. You will make a slight modification to make the screen background all white, so that the phone can be used as a flashlight. This example is not very creative, but can be used as a useful example. Download the complete source code.

To create an application in eclipse, selectFile> New> Android ProjectTo start the new Android Project Wizard.

Figure 5. New Android Project Wizard

Next, create a simple application with an activity and a UI layout in Main. xml. The layout contains a text element. You can modify this text element to display Android flashlight. The following list shows the simple layout.

Listing 1. Flashlight Layout

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:background="@color/all_white"><TextView      android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:text="@string/hello" android:textColor="@color/all_black"    android:gravity="center_horizontal"/></LinearLayout>

Create two color resources in strings. xml.

Listing 2. colors in strings. xml

<?xml version="1.0" encoding="utf-8"?><resources>    <string name="hello">Android FlashLight</string>    <string name="app_name">FlashLight</string>    <color name="all_white">#FFFFFF</color>    <color name="all_black">#000000</color></resources>

The main screen layout is definedall_white. In the strings. xml file, you can seeall_whiteIt is defined as an RGB Triplet with a value of # ffffff, that is, pure white.

The layout containsTextViewThis is actually a piece of static text. It cannot be edited. The text is set to black and passedgravityThe attribute is set to horizontally centered.

This application has a Java source file named flashlight. Java, as shown in the following list.

Listing 3. Flashlight. Java

package com.msi.flashlight;import android.app.Activity;import android.os.Bundle;public class FlashLight extends Activity {    /** Called when the activity is first created. */    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);    }}

This code is directly from the template code of the new project Wizard:

  • It is part of the Java package com. MSI. Flashlight.
  • It has two import:
    • An activity class
    • One bundle class
  • After the activity is initiated,onCreateThe method is called andsavedInstanceState. We don't need to care about this bundle. It is used only when the activity is paused and then resumed.
  • onCreateThe method overwrites the activity class method with the same name. It calls the superclassonCreateMethod.
  • PairsetContentView()Will be associated with the UI layout defined in the main. xml file. All content in Main. xml and strings. XML is automatically mapped to constants defined in the R. Java source file. Do not directly edit this file at any time because it changes with each build.

Run the application to see a white screen with black text.

Figure 6. Flashlight white screen

The androidmanifest. xml file for the flashlight application is displayed below.

Listing 4. androidmanifest. XML for flashlight

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"      package="com.msi.flashlight"      android:versionCode="1"      android:versionName="1.0.0">    <application android:icon="@drawable/icon" android:label="@string/app_name">        <activity android:name=".FlashLight"                  android:label="@string/app_name">            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application></manifest>

This file is automatically created by the android Developer Tools plug-in for eclipse. You do not need to do anything.

Of course, this application is not very powerful. However, if you want to read a book and do not want to disturb your sleeping lover, or if you want to check the fuse box in the basement when the power is down, this application is very convenient.

Back to Top

Conclusion

In this article, you have read about Android and built a small application. We hope that the examples in this article will arouse your interest in further exploring the Android platform. Android is expected to become an open-source platform that has a profound impact on the market. Its use will far surpass that of mobile phones.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.