Mobile Application Development
Unit-1
Android Introduction :
Android is an operating system based on Linux kernel, developed by Google. Linux is an Open
Source and free operating system and with some modifications on the Linux operating system, android
OS was developed. Linux OS is majorly used in server and Desktop operating system so the android
operating system is focused on touch screen mobile devices like smartphones and tablets Various
Platform for Mobile
Android OS: The Android operating system is the most popular operating system today. It is a
mobile OS based on the Linux Kernel and open-source software. The android operating system was
developed by Google. The first Android device was launched in 2008.
BlackBerry OS: The BlackBerry operating system is a mobile operating system developed by
Research In Motion (RIM). This operating system was designed specifically for BlackBerry handheld
devices.
iPhone OS / iOS : The iOS was developed by the Apple inc for the use on its device. The iOS
operating system is the most popular operating system today. It is a very secure operating system. The
iOS operating system is not available for any other mobiles.
Windows Mobile OS : The window mobile OS is a mobile operating system that was developed by
Microsoft. It was designed for the pocket PCs and smart mobiles.
Android API
An Application Programming Interface (API) is a particular set of rules (‘code’) and
specifications that programs can follow to communicate with each other. APIs are growing
exponentially every year.
The world of software moves fast. In earlier days data entered and processed in the same
system, but now the origin of the data and processing place is entirely different. We should be able to
access the data from anywhere at any time , that’s why we store this data in cloud storage.
For sending and receiving data from/to the server ,we want a middle man who is platform
independent.That middleman handles the requests and serves the response to the user .The below
diagram illustrates this better than words.
Android API
An Application Programming Interface (API) is a particular set of rules (‘code’) and specifications
that programs can follow to communicate with each other .
APIs are growing exponentially every year. The world of software moves fast. In earlier days data
entered and processed in the same system, but now the origin of the data and processing place is
entirely
different. We should be able to access the data from anywhere at any time , that’s why we store this
data in cloud storage .
For sending and receiving data from/to the server ,we want a middle man who is platform
independent.That middleman handles the requests and serves the response to the user .The below
diagram illustrates this better than words.
The End user sends a request , API executes the instruction then gets the data from the server
and responds to the user.
The End user sends a request , API executes the instruction then gets the data from the server
and responds to the user.
Types of API :
● SOAP API (Simple object Access Protocol)
● REST API (Representational state transfer)
Andriod Architecture
Android architecture contains a different number of components to support any android
device needs. Android software contains an open-source Linux Kernel having a collection of C/C++
libraries which are exposed through an application framework services.
Among all the components Linux Kernel provides main functionality of operating system
functions to smartphones and Dalvik Virtual Machine (DVM) provides a platform for running an
android application.
The main components of android architecture are following:-
● Applications
● Application Framework
● Android Runtime
● Platform Libraries
● Linux Kernel
Pictorial representation of android architecture with several main components and their sub
components-
Applications –
Applications is the top layer of android architecture . The pre-installed applications like
home, contacts, camera, gallery etc and third party applications downloaded from the play store like
chat applications, games etc. will be installed on this layer only.
It runs within the Android run time with the help of the classes and services provided by the
application framework.
Application framework –
Application Framework provides several important classes which are used to create an Android
application . It provides a generic abstraction for hardware access and also helps in managing the
user interface with application resources. Generally, it provides the services with the help of which
we can create a particular class and make that class helpful for the Applications creation.
It includes different types of services activity manager, notification manager, view system, package
manager etc. which are helpful for the development of our application according to the prerequisite.
Application runtime –
The Android Runtime environment is one of the most important part of Android . It contains
components like core libraries and the Dalvik virtual machine(DVM). Mainly , it provides the base
for the application framework and powers our application with the help of the core libraries .
Like Java Virtual Machine (JVM), Dalvik Virtual Machine (DVM) . It depends on the layer Linux
kernel for threading and low-level memory management. The core libraries enable us to implement
android applications using the standard JAVA or Kotlin programming languages.
Platform libraries –
The Platform Libraries include various C/C++ core libraries and Java based libraries such as Media,
Graphics, Surface Manager, OpenGL etc. to provide support for android development.
● Media library provides support to play and record audio and video formats.
● Surface manager responsible for managing access to the display subsystem.
● SGL and OpenGL both cross-language, cross-platform application program interface (API)
are used for 2D and 3D computer graphics.
● SQLite provides database support and FreeType provides font support.
● Web-Kit This open source web browser engine provides all the functionality to display
web content and to simplify page loading.
● SSL (Secure Sockets Layer) is security technology to establish an encrypted link between a
web server and a web browser.
Linux Kernel –
Linux Kernel is the heart of the android architectu re. It manages all the available drivers such as
display drivers, camera drivers, Bluetooth drivers, audio drivers, memory drivers, etc . which are
required during the runtime.
The Linux Kernel will provide an abstraction l ayer between the device hardware and the other
components of android architecture. It is responsible for management of memory, power, devices etc.
The features of Linux kernel are:
● Security: The Linux kernel handles the security between the application and the system.
● Memory Management: It efficiently handles the memory management thereby providing
the freedom to develop our apps.
● Process Management: It manages the process well, allocates resources to processes
whenever they need them.
● Network Stack : It effectively handles the network communication.
● Driver Model: It ensures that the application works properly on the device and hardware
manufacturers responsible for building their drivers into the Linux build.
Features of Android
● User Interface: The user interface of the Android operating system is straight forward, and
these features make it very user friendly.
● Multiple Language Support: Android supports multiple languages in its operating system
and one can change the language very easily based on one’s requirement, the International languages
supported are English, Germany, Chinese, Dutch, French, German, Japanese, Korean, Russian, and
many more also some native language of India is also Supported Like Hindi, Marathi, Gujarati,
Punjabi and many more.
● Multi-tasking: Android provides support to run apps and services in the background with
ease which allows the users to use multiple apps at the same time.
● Connectivity : Android has extensive support to the connectivity and it supports
connectivity such as WiFi, Bluetooth, Hotspot, CDMA, GSM, NFC, VOLTE, UBB, VPN, 3G
network band, and 4G Network Band.
● Extensive Application Support : Android have Play store which is used as the major tool
to download and update applications on the operating system, however, one can download the
installer(often called as APK file) and install it manually, but it is not much recommended as third
party applications could be prone to some security breach in the smartphones.
ANDROID SDK
Android SDK stands for Android Software Development Kit which is developed by Google
for Android Platform. With the help of Android SDK, we can create Android Apps easily.
About Android SDK
Android SDK is a collection of libraries and Software Development tools that are essential for
Developing Android Applications. Whenever Google releases a new version or update of Android
Software, a corresponding SDK also releases with it .
Components of Android SDK
Android SDK Components play a major role in the Development of Android applications.
Below are the important components:
1. Android SDK Tools
Android SDK tool is an important component of Android SDK. It consists of a complete set of
development and debugging tools. Below are the SDK developer tools:
● Android SDK Build tool.
● Android Emulator.
● Android SDK Platform-tools.
● Android SDK Tools.
2. Android SDK Build-Tools
Android SDK build tools are used for building actual binaries of Android App . The main functions
of Android SDK Build tools are built, debug, run and test Android applications.
3. Android Emulator
An Android Emulator is a device that simulates an Android device on your system. . In Android
Emulator the virtual android device is shown on our system on which we run the Android application
that we code.
4. Android SDK Platform-tools
Android SDK Platform-tools is helpful when we are working on a Project and they will show the error
messages at the same time. It is specifically used for testing .
5. Android SDK Tools
Android SDK tool is a component of SDK tool. It consists of a set of tools which and other Utilities
which are crucial for the development of Android Application. It contains the complete set of
Debugging and Development tools for android.
6. SDK Platforms
For Each Android Software, one SDK platform is available as shown below : Like in this Android
11.0(R) is installed. These are numbered according to the android version.
Eclipse Installation:
How to Install and Setup Eclipse IDE For Android App Development?
Android Application Development can be done using Android Studio as well as Eclipse IDE.
We can create android applications in Eclipse IDE using the ADT plugin. Eclipse is preferred for
creating small android applications. Eclipse IDE is an open-source software used by developers, it
contains a variety of plugins to develop software in different programming languages. We will be using
Eclipse IDE to set up Android App Development. First, we need to install Eclipse IDE, and then we
will be setting it up for Android App Development.
Steps to Install Eclipse IDE
1. To install Eclipse IDE, click on Download Eclipse
2. Download JDK (Java Development Kit) and Android Studio as well.
3. In File Explorer, go to Downloads – “Eclipse IDE” will be downloaded.
4. Open Eclipse IDE, choose Eclipse IDE for Java Developers and Install.
5. Eclipse IDE environment is ready, now it’s time to set up Android Development.
Steps to Setup Eclipse IDE for Android App Development
Step 1: Open Eclipse IDE.
Step 2: Select Help, Click on “Install New Software”
Looking to become an expert in Android App Development? Whether you're a student or a professional
aiming to advance your career in mobile app development, our course, "Android App Development
with Kotlin," available exclusively on GeeksforGeeks, is the perfect fit for you.
Step 3: Type “https://dl-ssl.google.com/android/eclipse/” in the “Work With” section and click on
Add. Further, a new Dialog box will appear, type Name – ADT Repository and Click on Add.
Step 4: You can see Developer Tools under Name – tick the box, then click Next. A dialog box will
appear, click on Next and then click on Finish. After that, Installation will begin.
The installation will take some time:
Step 5: After the installation is completed, Eclipse will be restarted. After the restart, a dialog box will
appear for setting up the Preferences. Click on Open Preferences then Click on Proceed. If the dialog
box does not appear then go to Eclipse -> Window -> Preferences.
Step 6: Browse the SDK Location of Android (C:\Program Files\Android\android-sdk) and Click
Apply.
Note 1: SDK Path is also present in Android Studio -> Tools -> SDK Manager -> Copy the Android
SDK Location path and paste it here.
Note 2: If in case after Step 6, if you are facing this issue “Could not find folder ‘tools’ inside SDK”
please refer to this article How to fix Could not find folder ‘tools’ inside SDK in Android?
Step 7: Click on Install new SDK then Next. Another dialog box will appear, Accept all three packages
and Click on Install.
After installation of packages, SDK Manager will appear for API Level Build Tools and System
Images installation. Click on Install.
Step 8: After installation is completed, Go to Eclipse then Select Window then Click on Android
Virtual Device Manager. A dialog box will appear, Select existing AVD and Click on Edit.
Fill in all the details as per the below image. Click OK.
Step 9: To create an android application, Select File -> New -> Other, and then the below dialog box
will appear Select Android -> Android Application Project then Click on Next. Follow the steps and
then click on Finish.
Step 10: Eclipse IDE setup is completed for Android Application Development.
Android Installation:
Install Android
Android supports java, c++, c# etc. language to develop android applications. Java is the officially
supported language for android. All the android examples of this site is developed using Java language
and Eclipse IDE.
Here, we are going to tell you, the required softwares to develop android applications using Eclipse
IDE.
There are two ways to install android.
1. By ADT Bundle
2. By Setup Eclipse Manually
1) By Android Studio
Eclipse IDE
Android SDK
Eclipse Plugin
If you download the Android Studio from android site, you don't need to have eclipse IDE, android
SDK and eclipse Plugin because it is already included in Android Studio.
How to setup Android for Eclipse IDE
In this page, you will learn what softwares are required for running an android application on eclipse
IDE. Here, you will be able to learn how to install the android SDK and ADT plugin for Eclipse IDE.
Let's see the list of software required to setup android for eclipse IDE manually.
1. Install the JDK
2. Download and install the Eclipse for developing android application
3. Download and Install the android SDK
4. Intall the ADT plugin for eclipse
5. Configure the ADT plugin
6. Create the AVD
7. Create the hello android application
1) Install the Java Development Kit (JDK)
For creating android application, JDK must be installed if you are developing the android application
with Java language. download the JDK
2) Download and install the Eclipse IDE
For developing the android application using eclipse IDE, you need to install the Eclipse. you can
download it from this location download the Eclipse. Eclipse classic version is recommended but we
are using the Eclipse IDE for JavaEE Developers.
3) Download and install the android SDK
First of all, download the android SDK. In this example we have installed the android SDK for
windows (.exe version).
Advertisement
Now double click on the exe file, it will be installed. I am using the android 2.2 version here.
4) Download the ADT plugin for eclipse
ADT (Android Development Tools) is required for developing the android application in the eclipse
IDE. It is the plugin for Eclipse IDE that is designed to provide the integrated environment.
For downloading the ADT, you need to follow these steps:
1) Start the eclipse IDE, then select Help > Install new software...
2) In the work with combo box, write https://dl-ssl.google.com/android/eclipse/
3) select the checkbox next to Developer Tools and click next
Advertisement
4) You will see, a list of tools to be downloaded here, click next
5) click finish
6) After completing the installation, restart the eclipse IDE
5) Configuring the ADT plugin
After the installing ADT plugin, now tell the eclipse IDE for your android SDK location. To do so:
1. Select the Window menu > preferences
2. Now select the android from the left panel. Here you may see a dialog box asking if you want to
send the statistics to the google. Click proceed.
3. Click on the browse button and locate your SDK directory e.g. my SDK location is C:\Program
Files\Android\android-sdk .
4. Click the apply button then OK.
6) Create an Android Virtual Device (AVD)
For running the android application in the Android Emulator, you need to create and AVD. For creating
the AVD:
1. Select the Window menu > AVD Manager
2. Click on the new button, to create the AVD
3. Now a dialog appears, write the AVD name e.g. myavd. Now choose the target android version
e.g. android2.2.
4. click the create AVD
Building you First Android application:
How to create the simple hello android application. We are creating the simple example of android
using the Eclipse IDE. For creating the simple example:
1. Create the new android project
2. Write the message (optional)
3. Run the android application
Hello Android Example
You need to follow the 3 steps mentioned above for creating the Hello android application.
1) Create the New Android project
For creating the new android studio project:
1) Select Start a new Android Studio project
PlayNext
Mute
Current Time 0:00
/
Duration 18:10
Loaded: 2.94%
Fullscreen
Backward Skip 10sPlay VideoForward Skip 10s
Advertisement
ADVERTISING
2) Provide the following information: Application name, Company domain, Project location and
Package name of application and click next.
3) Select the API level of application and click next.
4) Select the Activity type (Empty Activity).
5) Provide the Activity Name and click finish.
After finishing the Activity configuration, Android Studio auto generates the activity class and other
required configuration files.
Now an android project has been created. You can explore the android project and see the simple
program, it looks like this:
Advertisement
2) Write the message
File: activity_main.xml
Android studio auto generates code for activity_main.xml file. You may edit this file according to your
requirement.
1. <?xml version="1.0" encoding="utf-8"?>
2. <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/
android"
3. xmlns:app="http://schemas.android.com/apk/res-auto"
4. xmlns:tools="http://schemas.android.com/tools"
5. android:layout_width="match_parent"
6. android:layout_height="match_parent"
7. tools:context="first.javatpoint.com.welcome.MainActivity">
8.
9. <TextView
10. android:layout_width="wrap_content"
11. android:layout_height="wrap_content"
12. android:text="Hello Android!"
13. app:layout_constraintBottom_toBottomOf="parent"
14. app:layout_constraintLeft_toLeftOf="parent"
15. app:layout_constraintRight_toRightOf="parent"
16. app:layout_constraintTop_toTopOf="parent" />
17.
18. </android.support.constraint.ConstraintLayout>
19. }
File: MainActivity.java
1. package first.javatpoint.com.welcome;
2.
3. import android.support.v7.app.AppCompatActivity;
4. import android.os.Bundle;
5.
6. public class MainActivity extends AppCompatActivity {
7. @Override
8. protected void onCreate(Bundle savedInstanceState) {
9. super.onCreate(savedInstanceState);
10. setContentView(R.layout.activity_main);
11. }
12. }
To understand the first android application, visit the next page (internal details of hello android
example).
3) Run the android application
To run the android application, click the run icon on the toolbar or simply press Shift + F10.
The android emulator might take 2 or 3 minutes to boot. So please have patience. After booting the
emulator, the android studio installs the application and launches the activity. You will see something
like this:
Anatomy of Android Application:
There are four building blocks to an Android application:
• Activity
• Intent Receiver
• Service
• Content Provider
Not every application needs to have all four, but your application will be written with some
combination of these.
Once you have decided what components you need for your application, you should list them in a file
called AndroidManifest.xml. This is an XML file where you declare the components of your
application and what their capabilities and requirements are. We will discuss soon, what the
AndroidManifest.xml is responsible for.
Activity :
Activities are the most common of the four Android building blocks. An activity is usually a
single screen in your application. Each activity is implemented as a single class that extends the
Activity base class. Your class will display a user interface composed of Views and respond to events.
Most applications consist of multiple screens. For example, a text messaging application might have
one screen that shows a list of contacts to send messages to, a second screen to write the message to the
chosen contact, and other screens to review old messages or change settings. Each of these screens
would be implemented as an activity.
Intent and Intent Filters :
When a new screen opens, the previous screen is paused and put onto a history stack. The user
can navigate backward through previously opened screens in the history. Screens can also choose to be
removed from the history stack when it would be inappropriate for them to remain. Android retains
history stacks for each application launched from the home screen. Android uses a special class called
Intent to move from screen to screen. Intent describe what an application wants done. The two most
important parts of the intent data structure are the action and the data to act upon. Typical values for
action are MAIN (the front door of the application), VIEW, PICK, EDIT, etc. The data is expressed as
a Uniform Resource Indicator (URI). For example, to view a website in the browser, you would create
an Intent with the VIEW action and the data set to a Website-URI. new
Intent(android.content.Intent.VIEW_ACTION, ContentURI.create("http://anddev.org")); There is a
related class called an IntentFilter. While an intent is effectively a request to do something, an intent
filter is a description of what intents an activity (or intent receiver, see below) is capable of handling.
Activities publish their IntentFilters in the AndroidManifest.xml file.
Intent Receiver :
You can use an IntentReceiver when you want code in your application to execute in reaction to
an external event, for example, when the phone rings, or when the data network is available, or when
it's midnight. Intent receivers do not display a UI, although they may display Notifications to alert the
user if something interesting has happened. Intent receivers are also registered in AndroidManifest.xml,
but you can also register them from code using Context.registerReceiver().
Service :
A Service is code that is long-lived and runs without a UI. A good example of this is a media
player playing songs from a play list. In a media player application, there would probably be one or
more activities that allow the user to choose songs and start playing them. However, the music
playback itself should not be handled by an activity because the user will expect the music to keep
playing even after navigating to a new screen. In this case, the media player activity could start a
service using Context.startService() to run in the background to keep the music going. The system will
then keep the music playback service running until it has finished.
(You can learn more about the priority given to services in the system by reading Life Cycle of an
Android Application.) Note that you can connect to a service (and start it if it's not already running)
with the Context.bindService() method. When connected to a service, you can communicate with it
through an interface exposed by the service. For the music service, this might allow you to pause,
rewind, etc.
AndroidManifest.xml file in android
The AndroidManifest.xml file contains information of your package, including components of the
application such as activities, services, broadcast receivers, content providers etc.
It performs some other tasks also:
It is responsible to protect the application to access any protected parts by providing the
permissions.
It also declares the android api that the application is going to use.
It lists the instrumentation classes. The instrumentation classes provides profiling and other
informations. These informations are removed just before the application is published etc.
This is the required xml file for all the android application and located inside the root directory.
A simple AndroidManifest.xml file looks like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.javatpoint.hello"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Elements of the AndroidManifest.xml file:
The elements used in the above xml file are described below.
<manifest>
manifest is the root element of the AndroidManifest.xml file. It has package attribute that describes
the package name of the activity class.
<application>
Application is the subelement of the manifest. It includes the namespace declaration. This element
contains several subelements that declares the application component such as activity etc.
The commonly used attributes are of this element are icon, label, theme etc.
android:icon represents the icon for all the android application components.
android:label works as the default label for all the application components.
android:theme represents a common theme for all the android activities.
<activity>
activity is the subelement of application and represents an activity that must be defined in the
AndroidManifest.xml file. It has many attributes such as label, name, theme, launchMode etc.
android:label represents a label i.e. displayed on the screen.
android:name represents a name for the activity class. It is required attribute.
<intent-filter>
intent-filter is the sub-element of activity that describes the type of intent to which activity, service
or broadcast receiver can respond to.
<action>
It adds an action for the intent-filter. The intent-filter must have at least one action element.
<category>
It adds a category name to an intent-filter.
Unit IV