Android Notes Unit-1
Android Notes Unit-1
Android offers a unified approach to application development for mobile devices which
means developers need only develop 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 where as the first commercial version, Android 1.0, was released in
September 2008.
On June 27, 2012, at the Google I/O conference, Google announced the next Android
version, 4.1 Jelly Bean. Jelly Bean is an incremental update, with the primary aim of
improving the user interface, both in terms of functionality and performance.
The source code for Android is available under free and open source software licenses.
Google publishes most of the code under the Apache License version 2.0 and the rest, Linux
kernel changes, under the GNU General Public License version 2.
Why Android ?
Features of Android
Android is a powerful operating system competing with Apple 4GS
and supports great features. Few of them are listed below −
Beautiful UI :
1
Android OS basic screen provides a beautiful and intuitive user interface.
Connectivity :
2
GSM/EDGE, IDEN, CDMA, EV-DO, UMTS, Bluetooth, Wi-Fi, LTE, NFC and
WiMAX.
Storage :
3
SQLite, a lightweight relational database, is used for data storage purposes.
Media support :
4
H.263, H.264, MPEG-4 SP, AMR, AMR-WB, AAC, HE-AAC, AAC 5.1, MP3,
MIDI, Ogg Vorbis, WAV, JPEG, PNG, GIF, and BMP.
Messaging :
5
SMS and MMS
Web browser :
6
Based on the open-source WebKit layout engine, coupled with Chrome's V8
JavaScript engine supporting HTML5 and CSS3.
Multi-touch :
7
Android has native support for multi-touch which was initially made available in
handsets such as the HTC Hero.
Multi-tasking :
8
User can jump from one task to another and same time various application can run
simultaneously.
Resizable widgets :
9
Widgets are resizable, so users can expand them to show more content or shrink
them to save space.
Multi-Language :
10
Supports single direction and bi-directional text.
GCM :
11
Google Cloud Messaging (GCM) is a service that lets developers send short
message data to their users on Android devices, without needing a proprietary sync
solution.
Wi-Fi Direct :
12
A technology that lets apps discover and pair directly, over a high-bandwidth peer-
to-peer connection.
Android Beam :
13
A popular NFC-based technology that lets users instantly share, just by touching
two NFC-enabled phones together.
There are many android applications in the market. The top categories are:
● Entertainment
● Tools
● Communication
● Productivity
● Personalization
● Music and Audio
● Social
● Media and Video
● Travel and Local etc.
Apr08, 2021
Advantages and Disadvantages of
Google Android
Android Google as the name suggests, comes from the tech giant Google LLC. Android
Operating System is immensely popular across the globe and it’s evident from the fact that
Google Play Store offers more than 2 million apps to download and install in devices running
on it. A wide range of devices run on this OS including smartphones, tablets, watches, audio
players, TVs and PCs.
Like all good things, this popular OS has its advantages and disadvantages that we’ll explore
in this blog.
Advantages of Android :
• Android is an open-source platform allowing UI customization
Licensed under Apache, Android is an open source operating system whose codes developers
can change to build customized User Interface. App developers building applications for this
platform can get access to the core codes and are at a liberty to change the them to get the
customized outcomes. This is not possible when it comes to iOS and app have to strictly
adhere to the core code specifications when developing apps for the specific platform.
Disadvantages of Android
• Runs slow on low-specification devices
Android operating system is huge and occupies a lot of space. This is the reason that phones
with low hardware specifications run slow on this OS. Moreover, it comes with several
default apps that further slow down the smartphone operation. This leaves no scope of
downloading external apps and also leads to heating issues of the device.
All said and done, Android still continues to be extremely popular among smartphone users
worldwide as all types of devices support it. Apps for Android can be customized giving
users the effect that they want taking the platform’s popularity further ahead.
Installation Guide
Step 1: Head over to this link to get the Android Studio executable or zip file.
Click on the Save file button in the appeared prompt box and the file will start downloading.
Step 3: After the downloading has finished, open the file from downloads and run it. It will
prompt the following dialog box.
Click on next. In the next prompt, it’ll ask for a path for installation. Choose a path and hit
next.
Step 4: It will start the installation, and once it is completed, it will be like the image shown
below.
Click on next.
Step 5: Once “Finish” is clicked, it will ask whether the previous settings need to be
imported [if the android studio had been installed earlier], or not. It is better to choose the
‘Don’t import Settings option’.
Step 7: After it has found the SDK components, it will redirect to the Welcome dialog box.
Click on Next.
Choose Standard and click on Next. Now choose the theme, whether the Light theme or the
Dark one. The light one is called the IntelliJ theme whereas the dark theme is called
Dracula. Choose as required.
Click on the Next button.
Step 9: Click on Start a new Android Studio project to build a new app.
Hello Word Example
Before Writing a Hello word code, you must know about XML tags.To write hello word
code, you should redirect to App>res>layout>Activity_main.xml
To show hello word, we need to call text view with layout ( about text view and layout, you
must take references at Relative Layout and Text View ).
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView android:text="@string/hello_world"
android:layout_width="550dp"
android:layout_height="wrap_content" />
</RelativeLayout>
Need to run the program by clicking Run>Run App or else need to call shift+f10key.
Finally, result should be placed at Virtual devices as shown below
The next level of installation should contain selecting the activity to mobile, it specifies the
default layout for Applications.
At the final stage it going to be open development tool to write the application code.
Java
1 This contains the .java source files for your project. By default, it includes an
MainActivity.java source file having an activity class that runs when your app is
launched using the app icon.
res/drawable-hdpi
2
This is a directory for drawable objects that are designed for high-density screens.
res/layout
3
This is a directory for files that define your app's user interface.
res/values
4
This is a directory for other various XML files that contain a collection of
resources, such as strings and colours definitions.
AndroidManifest.xml
5
This is the manifest file which describes the fundamental characteristics of the app
and defines each of its components.
Build.gradle
Following section will give a brief overview of the important application files.
package com.example.helloworld;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
The <activity> tag is used to specify an activity and android:name attribute specifies the fully
qualified class name of the Activity subclass and the android:label attributes specifies a string
to use as the label for the activity. You can specify multiple activities using <activity> tags.
The action for the intent filter is named android.intent.action.MAIN to indicate that this
activity serves as the entry point for the application. The category for the intent-filter is
named android.intent.category.LAUNCHER to indicate that the application can be launched
from the device's launcher icon.
The @string refers to the strings.xml file explained below. Hence, @string/app_name refers
to the app_name string defined in the strings.xml file, which is "HelloWorld". Similar way,
other strings get populated in the application.
Following is the list of tags which you will use in your manifest
file to specify different Android application components −
<resources>
<string name="app_name">HelloWorld</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">MainActivity</string>
</resources>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="@dimen/padding_medium"
android:text="@string/hello_world"
tools:context=".MainActivity" />
</RelativeLayout>
This is an example of simple RelativeLayout which we will study in a separate chapter. The
TextView is an Android control used to build the GUI and it have various attributes like
android:layout_width, android:layout_height etc which are being used to set its width and
height etc.. The @string refers to the strings.xml file located in the res/values folder. Hence,
@string/hello_world refers to the hello string defined in the strings.xml file, which is "Hello
World!".
Running the Application
Let's try to run our Hello World! application we just created. I assume you had created your
AVD while doing environment set-up. To run the app from Android studio, open one of your
project's activity files and click Run icon from the tool bar. Android studio
installs the app on your AVD and starts it and if everything is fine
with your set-up and application, it will display following
Emulator window −
1. In Android Studio, we need to create an Android Virtual Device (AVD) that the emulator
can use to install and run your app. To create a new AVD:-
1.1 Open the AVD Manager by clicking Tools > AVD Manager.
1.2 Click on Create Virtual Device, at the bottom of the AVD Manager dialog. Then Select
Hardware page appears.
1.3 Select a hardware profile and then click Next. If we don?t see the hardware profile we
want, then we can create or import a hardware profile. The System Image page appears.
1.4 Select the system image for the particular API level and click Next. This leads to open a
Verify Configuration page.
2. In the toolbar, choose the AVD, which we want to run our app from the target device from
the drop-down menu.
3. Click Run.
Launch the Emulator without first running an app
To start the emulator:
While the emulator is running, we can run the Android Studio project and select the emulator
as the target device. We can also drag an APKs file to install on an emulator, and then run
them.
Using the emulator command, we will start an emulator. It is an alternative to run our project
or start through the AVD Manager.
or
For example, if we execute the emulator from Android Studio on a Mac, the default
command line will be similar as follows:
1. $ emulator -list-avds
An android component is simply a piece of code that has a well defined life cycle e.g.
Activity, Receiver, Service etc.
The core building blocks or fundamental components of android are activities, views,
intents, services, content providers, fragments and AndroidManifest.xml.
Activity
View
A view is the UI element such as button, label, text field etc. Anything that you see is a view.
Intent
Service
There are two types of services local and remote. Local service is accessed from within the
application whereas remote service is accessed remotely from other applications running on
the same device.
Content Provider
Fragment
Fragments are like parts of activity. An activity can display one or more fragments on the
screen at the same time.
AndroidManifest.xml
It contains informations about activities, content providers, permissions etc. It is like the
web.xml file in Java EE.
It is used to test the android application without the need for mobile or tablet etc. It can be
created in different configurations to emulate different types of real devices.