You are on page 1of 11

Introduction

Android is an open source and Linux-based Operating System for mobile devices such as smartphones and
tablet computers. Android was developed by the Open Handset Alliance, led by Google, and other companies.
Android offers a unified approach to application development for mobile devices which means developers need
to develop only for Android, and their applications should be able to run on different devices powered by
Android. The first beta version of the Android Software Development Kit (SDK) was released by Google in
2007, whereas the first commercial version, Android 1.0, was released in September 2008. The source code for
Android is available under free and open source software licenses.

The Essence of Mobile Devices


 There are potentially available to serve everywhere, any time.
 Interwoven into daily life – live, work, play, study
 Represents and intimately “knows” the user; much more than just a small computer, it represents the user
 Brings in the outside world – sensing, location, communication
 Now the dominant end-user device
Mobile Application Development Challenges
 Competitive, fluid vendor landscape (Apple, Android consortium incl. Amazon, RIM, HP) means apps need
to be multi-platform for wide adoption
 No “standard” device (iOS, Windows Phone devices)
 Low bandwidth input and limited screen size
 Unreliability in connectivity and device (network access, power, ambient light)
 Integration tradeoffs with cloud and enterprise services

Application Development Support


 3rd Generation Object-Oriented Languages (iOS – Objective C, Android – Java/Kotlin, Windows Phone –
C# )
 Scripting languages (JavaScript, Ruby)
 Cross-platform frameworks – Titanium, RhoMobile, Xamarin, PhoneGap
 C and C++
 Integrated into “frameworks” specifically for mobile application development

Features of Android
Android is a powerful operating system competing with Apple 4GS and support great features. Few of them are
listed below:

Feature Description
Beautiful UI Android OS basic screen provides a beautiful and intuitive user interface.
Connectivity GSM/EDGE, IDEN, CDMA/UMTS, Bluetooth, Wi-Fi, LTE, NFC and WiMAX.
Storage SQLite, a lightweight relational database, is used for data storage purposes.
Messaging SMS and MMS
Web browser Based on the open-source WebKit layout engine, coupled with Chrome's V8 JavaScript
engine supporting HTML5 and CSS3.
Multi-touch Android has native support for multi-touch which was initially made available in
handsets such as the HTC Hero.
Multi-tasking User can jump from one task to another and same time various application can run
simultaneously.
Resizable widgets Widgets are resizable, so users can expand them to show more content or shrink them to
save space
GCM Google Cloud Messaging (GCM) is a service that let developers send short message data
to their users on Android devices, without needing a proprietary sync solution.

Mobile Application Development Page 1 of 11


Android Beam A popular NFC-based technology that let users instantly share, just by touching two
NFC-enabled phones together.

TOOLS FOR APPLICATION DEVELOPMENT

Android Software Development Kit (SDK)


 Provides the Java framework classes
 Compiles to java bytecode
 Class framework is updated with every OS release

Android Native Development Kit (NDK)


C/C++ tool chain for compiling to machine code

Android platform tools


1. adb (android debug bridge) : runs and debugs apps from your devmachine
2. Android developer tools
3. Android studio

IDE Support
 Open IDEs – Android Studio for Android
 Proprietary (Xcode for iOS, MS Visual Studio)
 Testing tools (test management, unit tests)
 Performance profiling tools
 Software emulators
 Sensor injection (GPS, accelerometer, others)

ARCHITECTURE
Android operating system is a stack of software components which is roughly divided into five sections and
four main layers as shown below in the architecture diagram.

Mobile Application Development Page 2 of 11


i). Linux kernel
At the bottom of the layers is Linux (Linux 2.6), which provides basic system functionality such as process
management, memory management, device management like camera, keypad, display etc. Also, the kernel
handles all the things that Linux is really good at, such as networking and a vast array of device drivers, which
take the pain out of interfacing to peripheral hardware.

ii). Libraries
On top of Linux kernel there is a set of C/C++ libraries that are included to fulfill a wide and diverse range of
functions including 2D and 3D graphics drawing, Secure Sockets Layer (SSL) communication responsible for
Internet security, SQLite database management, audio and video playback, bitmap and vector font rendering,
display subsystem and graphic layer management and an implementation of the standard C system library (libc).
In practice, the typical Android application developer will access these libraries solely through the Java based
Android core library APIs. In the event that direct access to these libraries is needed, this can be achieved using
the Android NDK.

iii). Android Runtime


This is the third section of the architecture and available on the second layer from the bottom. This section
provides Dalvik Virtual Machine (DVM) or Android-Runtime Engine (ART). The DVM enables every Android
application to run in its own process, with its own instance of the Dalvik virtual machine.

iv). Application Framework


The Application Framework layer provides many higher-level services to applications in the form of Java
classes. Application developers are allowed to make use of these services in their applications. This framework
implements the concept that Android applications are constructed from reusable, interchangeable and
replaceable components.

v). Applications
Located at the top of the Android software stack are the applications. These comprise both the native
applications provided with the particular Android implementation and the third party applications installed by
the user after purchasing the device.
Applications are predominantly written in Java or Kotlin using the Android Software Development Kit and
compiled down to bytecode format within the Android Studio build environment

APPLICATIONS COMPONENT
Application components are the essential building blocks of an Android application. These components are
loosely coupled by the application manifest file AndroidManifest.xml that describes each component of the
application and how they interact.
The following four main components that can be used within an Android application:

Components Description
Activities They dictate the UI and handle the user interaction to the smartphone
screen.
Services They handle background processing associated with an application.

Broadcast Receivers They handle communication between Android OS and applications.

Content Providers They handle data and database management issues.

Mobile Application Development Page 3 of 11


Activities
An activity represents a single screen with a user interface. For example, an email application might have one
activity that shows a list of new emails, another activity to compose an email, and one for reading emails. If an
application has more than one activity, then one of them should be marked as the activity that is presented when
the application is launched.
An activity is implemented as a subclass of Activity class as follows:

public class MainActivity extends Activity


{

Services
A service is a component that runs in the background to perform long-running operations. For example, a
service might play music in the background while the user is in a different application, or it might fetch data
over the network without blocking user interaction with an activity. A service is implemented as a subclass of
Service class as follows:

public class MyService extends Service


{

Broadcast Receivers
Broadcast Receivers simply respond to broadcast messages from other applications or from the system. For
example, applications can also initiate broadcasts to let other applications know that some data has been
downloaded to the device and is available for them to use, so this is broadcast receiver who will intercept this
communication and will initiate appropriate action.
A broadcast receiver is implemented as a subclass of BroadcastReceiver class and each message is broadcasted
as an Intent object.

public class MyReceiver extends BroadcastReceiver


{

Content Providers
A content provider component supplies data from one application to others on request. Such requests are
handled by the methods of the ContentResolver class. The data may be stored in the file system, the database or
somewhere else entirely.
A content provider is implemented as a subclass of ContentProvider class and must implement a standard set
of APIs that enable other applications to perform transactions.

public class MyContentProvider extends ContentProvider


{

Additional Components
The following are additional components which will be used in the construction of above mentioned entities,
their logic, and wiring between them. These components are:

Mobile Application Development Page 4 of 11


Components Description
Fragments Represent a behavior or a portion of user interface in an Activity.

Views UI elements that are drawn onscreen including buttons, lists forms etc.
Layouts View hierarchies that control screen format and appearance of the views.
Intents Messages wiring components together. It generally defines an intention to
do some work.
Resources External elements, such as strings, constants and drawable pictures.
Manifest Configuration file for the application.

The development process


An Android app project begins with an idea and a definition of the requirements necessary to realize that idea.
As the project progresses, it goes through design, development, and testing as shown below:

i). Defining the idea and its requirements: Most apps start with an idea of what it should do, bolstered by
market and user research. During this stage the app's requirements are defined.
ii). Prototyping the user interface: Use drawings and prototypes to show what the user interface would look
like, and how it would work.
iii). Developing and testing the app: An app consists of one or more activities. For each activity you can use
Android Studio to do the following, in no particular order:
 Create the layout: Place UI elements on the screen in a layout, and assign string resources and menu
items, using the Extensible Markup Language (XML).
 Write the Java code: Create source code for components and tests, and use testing and debugging tools.
 Register the activity: Declare the activity in the manifest file.
 Define the build: Use the default build configuration or create custom builds for different versions of
your app.
iv). Publishing the app: Assemble the final APK (package file) and distribute it through channels such as the
Google Play.

Creating a Hello World Application


i). Create an Android Virtual Device (AVD) on which the emulator will run
ii). Create an Android Project using the New Project Wizard
iii). View and Edit the generated project code
iv). Compile project and sign, install and run the application on the emulator

Mobile Application Development Page 5 of 11


Steps in creating and running an Android application

EXAMPLE

Create Android Application

Step 1 – create an Android Virtual Device


Select Tools ->AVD Manager or From Android Start Screen, select configure-> AVD Manager

If a suitable AVD is listed then use that otherwise click New and then Create New Android Device dialogue
will be shown as shown below:

Mobile Application Development Page 6 of 11


• Enter a name by which you want to refer to the AVD
• Select a Target.
• Click Create AVD
• Close the Dialogue window

Step 2 - create an Android project


• Select File -> New -> New Project
• Make sure Create Activity and EmptyActivity are selected. Empty Activity template provides a single
activity accompanied by a single layout resource for the screen
• Complete the form as shown:
– Name: HelloAndroid - name of the project
– Package Name: com.example.helloandroid
– Language: Java
• Click Finish

The previous command will create a set of files and folders for the project

Mobile Application Development Page 7 of 11


Generated XML file defining the
app configuration

Generated Java file in the src folder.


We’ll edit this.

Generated XML file


defining the layout

Step 3 – view the Java code


Open the generated Java file An Android Activity corresponds
to a Screen or Window

onCreate() is
automatically
called when the
activity loads

Then edit the Java code as shown below

Mobile Application Development Page 8 of 11


package example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState); A TextView is a View
TextView tv = new TextView(this); capable of displaying Text
tv.setText("Hello World says Android");
setContentView(tv);
}
}

Step 4 – Compile, sign, install and run


• Select Run
• The code will be compiled and any errors reported (there shouldn’t be any in this case)
• If the emulator is not already running it will launch (this takes some time) and eventually the application
will install and run on the emulator
• Leave the emulator running as this will speed the process next time you run this or another application.

The following is the screen shot of app running on the emulator

Creating the UI using XML

Step One
Mobile Application Development Page 9 of 11
In the above example, we created the UI layout in Java code. However the Android’s preferred method is to use
an XML layout file
res\layout\activity_main.xml
<RelativeLayout …….>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</RelativeLayout>

Step Two
In the file HelloAndroid.java, modify the following statement as shown below:
setContentView(R.layout.activity_main);
res\values\strings.xml
<string name="hello_world">Hello world!</string>

Mobile Application Development Page 10 of 11


Applications, Activities, Views

1
Application (.apk file) AndroidManifest.xml

*
Activity

*
*
View

• An application is packaged into a .apk file and has one manifest file
• An application may contain many Activities. An Activity is created as a class that inherits from class
Activity
• An Activity can contain many Views. Each View is an instance of a class that inherits from class View.
• Views can be nested so a View can contain other Views

Compilation and Running of the app


Dalvik EXecutable (DEX) is Android compiled form of an app. The compiled Java code, along with some other
resources, is placed in a bundle of files called an Android application package (APK), and this is what the
Dalvik Virtual Machine (DVM) or Android-Runtime Engine (ART) needs to run the app. The Android
Runtime (ART) uses a process referred to as Ahead-of-Time (AOT) compilation to translate the bytecode
down to the native instructions required by the device processor. This process is shown below

Dalvik Virtual
Machine or
Android
Runtime Engine

Mobile Application Development Page 11 of 11

You might also like