Xathrya Sabertooth |
Introduction to Android and Android Application Development Posted: 17 Sep 2013 05:16 PM PDT This article will give a short summary of what should be known when developing Android application. Table of Contents
Android InsightThe Android Operating SystemAndroid is a operating system based on Linux Operating System. The project is lead by Google with a consortium of Open Handset Alliance. Nowadays, Android is used as some of smartphones and tablets operating system. Moreover, there is a project to port Android to x86 (a common PC). Android is a major player in smartphone OS beside Windows Phone, iOS, etc. Android system supports background processing, provides a rich user interface library, supports 2-D and 3-D graphics using OpenGL libraries, access to the file system and embedded SQLite database. Platform ComponentAndroid system is a full software stack which is typically defined into the following four areas:
How to Develop Android ApplicationsAndroid applications are primarily written in the Java programming language. During development the developer creates the Android specific configuration files and writes the application logic in the Java programming language. The Java source files are converted to Java class files by the Java compiler. The Android SDK contains a tool called dx which converts Java class files into a These The The resulting The ADT and Android Studio tools perform these steps transparently to the user, i.e. if the user selects that the application should be deployed, the whole Android application ( ArchitectureThe architecture discussed in this section is the architecture of Android. Android can be referred as software stack of different layer, where each layer is a group of several program components. These levels define abstraction on device and provide same API for application on above. Linux KernelThe kernel space. This area is controlled directly by Linux kernel and the basic layer of Android OS. The whole Android OS is built on top of the Linux 2.6 Kernel with some further architectural changes made by Google. It is this Linux that interacts with the hardware and contains all the essential hardware drivers. Drivers are programs that control and communicate with the hardware. For example, consider the Bluetooth function. All devices has a Bluetooth hardware in it. Therefore the kernel must include a Bluetooth driver to communicate with the Bluetooth hardware. The Linux kernel also acts as an abstraction layer between the hardware and other software layers. Android uses the Linux for all its core functionality such as Memory management, process management, networking, security settings etc. As the Android is built on a most popular and proven foundation, it made the porting of Android to variety of hardware, a relatively painless task. LibrariesAndroid Native Libraries layer is the layer that enables the device to handle different types of data. This libraries are written in C or C++ language and are specific for a particular hardware. Some important libraries: Surface Manager: It is used for compositing window manager with off-screen buffering. Off-screen buffering means you cant directly draw into the screen, but your drawings go to the off-screen buffer. There it is combined with other drawings and form the final screen the user will see. This off screen buffer is the reason behind the transparency of windows. Media framework: Media framework provides different media codecs allowing the recording and playback of different media formats SQLite: SQLite is the database engine used in android for data storage purposes WebKit: It is the browser engine used to display HTML content OpenGL: Used to render 2D or 3D graphics content to the screen RuntimeConsists of Dalvik Virtual Machine and Core Java Libraries. Android use a special virtual machine, i.e. the Dalvik Virtual Machine to run java based application. It is similar to standard Java Virtual Machine (JVM) however using stripped down and optimized one. The bytecode between Dalvik is also different from Java bytecode. Thus, you cannot run Java class files on Android directly. They need to get converted to Dalvik bytecode format. These are different from Java SE and Java ME libraries. However these libraries provides most of the functionalities defined in the Java SE libraries. Application FrameworkThese are the blocks that our applications directly interacts with. These programs manage the basic functions of phone like resource management, voice call management etc. As a developer, you just consider these are some basic tools with which we are building our applications. Important blocks of Application framework are: Activity Manager: Manages the activity life cycle of applications Content Providers: Manage the data sharing between applications Telephony Manager: Manages all voice calls. We use telephony manager if we want to access voice calls in our application. Location Manager: Location management, using GPS or cell tower Resource Manager: Manage the various types of resources we use in our Application ApplicationThe top layer, also referred as user space. In this layer, our application will reside and run. Security and PermissionsSecurity ConceptThe Android system installs every Android application with a unique user and group ID. Each application file is private to this generated user, e.g. other applications cannot access these files. In addition each Android application is started in its own process. Therefore, by means of the underlying Linux operating system, every Android application is isolated from other running applications. If data should be shared, the application must do this explicitly, e.g. via a service or a content provider. Permission ConceptAndroid contains a permission system and predefines permissions for certain tasks. Every application can request required permissions and also define new permissions. For example an application may declare that it requires access to the Internet. Permissions have different levels. Some permissions are automatically granted by the Android system, some are automatically rejected. In most cases the requested permissions are presented to the user before the installation of the application. The user needs to decide if these permissions are given to the application. If the user denies a required permission, the related application cannot be installed. The check of the permission is only performed during installation, permissions cannot be denied or granted after the installation. An Android application declares its required permissions in its Conventions and API LevelAPI VersionAPI Level is an integer value that uniquely identifies the framework API revision offered by a version of Android platform. The Android platform provides a framework API that applications can use to interact with the underlying Android system. The framework API consists of:
Each successive version of the Android platform can include updates to the Android application framework API that it delivers. Updates to the framework API are designed so that the new API remains compatible with earlier versions of the API. That is, most changes in the API are additive and introduce new or replacement functionality. As parts of the API are upgraded, the older replaced parts are deprecated but are not removed, so that existing applications can still use them. In a very small number of cases, parts of the API may be modified or removed, although typically such changes are only needed to ensure API robustness and application or system security. All other API parts from earlier revisions are carried forward without modification. Android Project and Package NameThe base package for the projects is always the same as the project name, e.g. if you are asked to create a project called com.vogella.android, then the corresponding package name is com.vogella.android. The application name, which must be entered on the Android project generation wizard, is not always predefined. In this case choose a name you like. Development ToolsAndroid SDKSoftware Development Kit (SDK) is a collection of tools and source code necessary to create, compile, and package a certain application. Thus, Android SDK is a SDK to create, compile, and package an application for Android. Most of these tools are command line. The primary language used at SDK is Java programming language. The Android SDK contains Android debug bridge (adb), a tool which allows us to connect to a virtual or even real android. Using this, we can manage the device and debugging application. Android NDKNative Development Kit (NDK) or Android NDK, is similar to Android SDK. Android NDK is targeted to expert in C\C++ who want to explore more into lower level. The primary language used at NDK is C\C++ programming language. Android Developer Tools and Android StudioFor developing an Android application, Google has provided graphical development environment. There are two flaovrs you can choose: Eclipse and IntelliJ IDE. Using Eclipse IDE, it means we should install a plugin so the Android developing process can be done. This is called Android Development Tool (ADT). The counterparts using IntelliJ IDE and has been tweaked to fulfill the duty. It’s called Android Stutio. The Android Developer Tools (ADT) are based on the Eclipse IDE and provide additional functionalities to develop Android applications. ADT is a set of components (plug-ins) which extend the Eclipse IDE with Android development capabilities. Both tools contain all required functionalities to create, compile, debug and deploy Android applications from the IDE. They also allow the developer to create and start Android virtual devices for testing. Both tools provide specialized editors for Android specific files. Most of Android configuration files are based on XML. In this case these editors allow you to switch between the XML representation of the file and a structured user interface for entering the data. Android Developer ToolsEclipse provides a perspective for interacting with Android Virtual Device and your Android application program. This is included on everytime you install plugin for Eclipse. DDMS – Dalvik Debug Monitor ServiceSelect Window → Open Perspective → Other… → DDMS to open this perspective. It groups several Eclipse views which can also be used independently. On the left side it shows you the connected Android devices and the running processes on the device. The right side is a stack of views with different purposes. You can select processes and trigger actions from the toolbar, e.g. start a trace or stop the process. Emulator ControlSimulate phone calls and SMS on the AVD. It also allows the application to set the current geo position. File ExplorerBrowse the filesystem on Android Virtual Device. Android Application ComponentsAndroid applications can consists out of four components:
ActivitiesAn activity represents the visual representation of an Android application. An Android application can have several activities. Activities use views and fragments to create the user interface and to interact with the user. Both elements are described in the next sections. ServicesA service performs tasks without providing an user interface. They can communicate with other Android components for example via broadcast receivers and notify the user via the notification framework in Android. Broadcast ReceiversA broadcast receiver (receiver) can be registered to receive system messages and intents. A receiver gets notified by the Android system, if the specified event occurs. For example you can register a receiver for the event that the Android system finished the boot process. Or you can register for the event that the state of the phone changes, e.g. someone is calling. Content ProviderA content provider (provider) provides a structured interface to application data. A provider can be used for accessing data within one application but can also be used to share data with other applications. Android contains an SQLite database which is frequently used in conjunction with a content provider. The SQLite database would store the data, which would be accessed via the provider. Resources and Important FilesAndroid Manifest FileThe components and settings of an Android application are described in the All activities, services and content providers components of the application must be statically declared in this file. Broadcast receiver can be defined statically in the manifest file or dynamically at runtime in the application. The Android manifest file must also contain the required permissions for the application. For example if the application requires network access it must be specified here. Following is the example of Android Manifest File: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="de.vogella.android.temperature" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".Convert" 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> <uses-sdk android:minSdkVersion="9" /> </manifest> The Google Play requires that every Android application uses its own unique package. Therefore it is a good habit to use your reverse domain name as package name. This will avoid collisions with other Android applications.
The The intent filter part in the Android manifest file, tells the Android runtime that this activity should to registered as possible entry point into the application and made available in the launcher of the Android system. The action define that is can be started The The Resources FilesAndroid supports that resources, like images and certain XML configuration files, can be keep separate from the source code. Resource files must be placed in the Resource IDs and R.javaEvery resource file gets an ID assigned by the Android build system. The If you add a new resource file, the corresponding reference is automatically created in The Android system provides methods to access the corresponding resource files via these IDs. For example to access a String with the DeploymentIn general, you can use several method to deploy an application to your device. Those are by USB transfer, email the application, use Google Play, etc. The following sections will highlights the most common ones and common deployment process. There is also a specific article discussing this material. You can check it on this link. Deployment via EclipseTurn on USB Debugging on your device in the settings. Select in the settings of your device Applications → Development, then enable USB debugging. You may also need to install the a driver for your mobile phone. Linux and Mac OS usually work out of the box while an Windows OS typically requires the installation of a driver. Please note that the Android version you are developing for must be the installed version on your phone. If you have only one device connected and no emulator running, the Android develoment tools will automatically deploy to this device. If you have several connected you can selected which one shoudl be used. Export ApplicationAndroid application must be signed before they can get installed on an Android device. During development Eclipse signs your application automatically with a debug key. If you want to install your application without the Eclipse IDE you can right-click on it and select Android Tools → Export Signed Application Package. This wizard allows to use an existing key or to create a new one. Please note that you need to use the same signature key in Google Play (Google Market) to update your application. If you loose the key you will NOT be able to update your application ever again. Make sure to backup your key. Via External SourceAndroid allow to install applications also directly. Just click on a link which points to an .apk file, e.g. in an email attachment or on a webpage. Android will prompt you if you want to install this application. This requires a setting on the Android device which allows the installation of non-market application. Typically this setting can be found under the “Security” settings. Google PlayGoogle Play requires a one time fee, currently 25 Dollar. After that the developer can directly upload his application and the required icons, under Google Play Publishing . Google performs some automatic scanning of applications, but no approval process is in place. All application, which do not contain malware, will be published. Usually a few minutes after upload, the application is available. |
You are subscribed to email updates from Xathrya Sabertooth To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google Inc., 20 West Kinzie, Chicago IL USA 60610 |
Tidak ada komentar:
Posting Komentar