0% found this document useful (0 votes)
10 views87 pages

MAD Unit 1

The document outlines the basics of Android programming, focusing on the Android 4.1 Jelly Bean SDK, the Android software stack, and the installation of the Android SDK. It provides a detailed explanation of the Android architecture, including its layers and components, as well as instructions for creating an Android application project using Eclipse. Additionally, it covers the use of TextView controls and the structure of Android application files.

Uploaded by

Sindhuja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views87 pages

MAD Unit 1

The document outlines the basics of Android programming, focusing on the Android 4.1 Jelly Bean SDK, the Android software stack, and the installation of the Android SDK. It provides a detailed explanation of the Android architecture, including its layers and components, as well as instructions for creating an Android application project using Eclipse. Additionally, it covers the use of TextView controls and the structure of Android application files.

Uploaded by

Sindhuja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 87

Android Programming (R15)

UNIT - 1

RCEW, Pasupula (V), Nandikotkur Road,


Near Venkayapalli, KURNOOL 1
Previous Class

RCEW, Pasupula (V), Nandikotkur Road,


Near Venkayapalli, KURNOOL
CONTENTS

• The Android 4.1 jelly Bean SDK, Understanding


the Android Software Stack, installing the
Android SDK, Creating Android Virtual Devices,
Creating the First Android Project, Using the
Text view Control, Using the Android Emulator,
The Android Debug Bridge(ADB), Launching
Android Applications on a Handset.

RCEW, Pasupula (V), Nandikotkur Road,


Near Venkayapalli, KURNOOL
What is Android
• Android is an operating system that is based on a
modified version of Linux for mobile devices such
as smartphones and tablet computers.
• It was originally developed by a startup of the same
name, Android, Inc. In 2005
• Google purchased Android and took over its
development work.
• Android has beaten Apple iOS, being the leading mobile
operating system from first quarter of 2011
• Google wanted Android to be open and free.
• The main advantage of adopting Android is
that it offers a unified approach to application
development.
• Developers need only develop for Android,
and their applications should be able to run
on numerous different devices, as long as the
devices are powered using Android.

RCEW, Pasupula (V), Nandikotkur Road,


Near Venkayapalli, KURNOOL
ANDROID VERSION RELEASE DATE CODENAME
1.1 9 February 2009
V 1.5 30 April 2009 Cupcake
A 1.6 15 September 2009 Donut
e 2.0/2.1 26 October 2009 Eclair
n 2.2 20 May 2010 Froyo
r 2.3 6 December 2010 Gingerbread
d 3.0/3.1/3.2 22 February 2011 Honeycomb
s 4.0 19 October 2011 Ice Cream Sandwich
r 4.1 July 13, 2012 Jelly Bean
i 4.4 Sep 3, 2013 KitKat
o 5.0/5.1 Nov 12, 2014 Lollipop
o 6.0 May 28, 2015 Marshmallow
i
n 7.0
8.0 – 8.1
Aug or Sept 2016
2017
Nougat
Oreo
d
s 9.0
10.0
2018
2019
Pie
Android Q
11 2020
ANDROID 4.1 JELLY BEAN SDK
• All the features of Android 4.0
• Released with new features for developers in July
2012
Features of Android 4.1
• Project Butter - UI faster and more responsive
• Faster speech recognition
• Improved notification system
• Supports new languages
• Predictive keyboard
• Auto-arranging Home screen
• Helpful for visually impaired users
• Improved Camera app
Features of Android 4.1
• Better communication in Jelly Bean (NFC,
Bluetooth)
• Improved Google Voice search
• Face Unlock
• Google Now
• Google Play Widgets
• Faster Google Search
• Supports antipiracy
Android Software Stack
Android Software Stack
The Android OS is roughly divided into five sections
in four main layers:
1. Linux kernel
2. Native libraries (middleware),
3. Android Runtime
4. Application Framework
5. Applications
Android Software Stack
The Android OS is roughly divided into five sections in four main layers:
• Linux kernel — It is the heart of android architecture that exists at the root of
android architecture. Linux kernel is responsible for device drivers, power
management, memory management, device management and resource access.
• Libraries — These contain all the code that provides the main features of an
Android OS. For example,
– SQLite Library used for data storage and light in terms of mobile memory
footprints and task execution.
– WebKit Library mainly provides Web Browsing engine and a lot more related
features.
– The surface manager library is responsible for rendering windows and
drawing surfaces of various apps on the screen.
– The media framework library provides media codecs for audio and video.
– The OpenGl (Open Graphics Library) and SGL(Scalable Graphics Library) are
the graphics libraries for 3D and 2D rendering, respectively.
– The FreeType Library is used for rendering fonts
• Android runtime — In android runtime, there are
core libraries and DVM (Dalvik Virtual Machine)
which is responsible to run android application.
• DVM is like JVM but it is optimized for mobile
devices.
• It consumes less memory and provides fast
performance.
• The Dalvik VM makes use of Linux core features
like memory management and multi-threading,
which is intrinsic in the Java language.
• The Dalvik VM enables every Android application
to run in its own process, with its own instance of
the Dalvik virtual machine.
DVM
• Android apps execute on
Dalvik VM, a “clean-room
(means not inherit copyright-
based license restrictions)”
implementation of JVM
– Dalvik optimized for efficient
execution
– Dalvik: register-based VM(no
PUSH or POP operatins), unlike
Oracle’s stack-based JVM
– Java .class bytecode translated to
Dalvik EXecutable (DEX)
bytecode, which Dalvik interprets

14
• Application framework — Android framework includes Android
API's such as UI (User Interface), telephony, resources, locations, Content
Providers (data) and package managers. It provides a lot of classes and
interfaces for android application development.
• Activity Manager: manages the life cycle of an applications and
maintains the back stack as well so that the applications running on
different processes has smooth navigations.
• Package Manager: keeps track of which applications are installed in
your device.
• Window Manager : Manages windows which are java programming
abstractions on top of lower level surfaces provided by surface
manager.
• Telephony Managers: manages the API which is use to build the
phone applications
• Content Providers: Provide feature where one application can share
the data with another application. like phone number , address, etc
• View Manager : Buttons , Edit text , all the building blocks of UI,
event dispatching etc.

15
• Applications — All applications such as home,
contact, settings, games, browsers are using
android framework that uses android runtime and
libraries.
• Any applications that you write are located at this
layer.

16
INSTALLING THE ANDROID SDK
• For developing native Android applications that you can publish
on the Google Play marketplace, you need to install the
following four applications:
1. The Java Development Kit (JDK) can be downloaded
from http://oracle.com/technetwork/java/javase/downloads/i
ndex.html.
2. The Eclipse IDE can be downloaded
from http://www.eclipse.org/downloads/.
3. The Android Platform SDK Starter Package can be download
from http://developer.android.com/sdk/index.html.
4. The Android Development Tools (ADT) Plug-in can be
downloaded from http://developer.android.com/sdk/eclipse-
adt.html. The plug-in contains project templates and Eclipse
tools that help in creating and managing Android projects.
Install JDK

RCEW, Pasupula (V), Nandikotkur Road,


Near Venkayapalli, KURNOOL
Install JDK
Android SDK installation
Android SDK installation
Android SDK installation
Android SDK installation
Android SDK installation
Android SDK installation
Installing Eclipse

RCEW, Pasupula (V), Nandikotkur Road,


Near Venkayapalli, KURNOOL
Installing Eclipse
Installing Eclipse
Installing the Android Development
Tools (ADT) Plug-in
To install the ADT plug-in, select the Help, Install New Software... option
Installing the Android Development
Tools (ADT) Plug-in
Installing the Android Development
Tools (ADT) Plug-in
Installing the Android Development
Tools (ADT) Plug-in
Android Virtual Devices (AVDs)
• Android Virtual Device (AVD) to be used for testing your
Android applications.
• An AVD is an emulator instance.
• AVD consists of a hardware profile; a mapping to a
system image; as well as emulated storage, such as a
secure digital (SD) card.
Session Outcome

End of today session:


Student can be able to
understand OOP concepts

RCEW, Pasupula (V), Nandikotkur Road,


Near Venkayapalli, KURNOOL
Android Programming (R15)
UNIT - 1

1
CONTENTS

• The Android 4.1 jelly Bean SDK, Understanding


the Android Software Stack, installing the
Android SDK, Creating Android Virtual Devices,
Creating the First Android Project, Using the
Text view Control, Using the Android Emulator,
The Android Debug Bridge(ADB), Launching
Android Applications on a Handset.
FIRST ANDROID PROJECT
• To create an application,
– open Eclipse and choose File, New, Android
Application Project (or)
– click the Android Project Creator icon on the
Eclipse toolbar, (or)
– select the File, New, Other option. A dialog box
appears asking you to select the wizard you
want to use for the new application.
Select Android Application Project and
click Next.
• src — Contains the .java source files
for your project. The
HelloWorldActivityApp.java file is
the source file for your activity. The
Java file is listed under the package
name for your project, which in this
case is
com.androidunleashed.helloworldap
p
• gen — Contains the R.java file, a
compiler-generated file that
references all the resources found in
your project. YOU SHOULD NOT
MODIFY THIS FILE. All the resources in
your project are automatically
compiled into this class so that you
can refer to them using the class.
• Android 4.1 library — This item contains one file,
android.jar, which contains all the class libraries
needed for an Android application.
• assets — This folder contains all the assets used by
your application, such as HTML, text files,
databases, etc.
• bin — This folder contains the files built by the ADT
during the build process. In particular, it generates
the .apk file (Application Package). An .apk file is
the binary file of an Android application. It
contains everything needed to run an Android
application.
• res — This folder contains all the resources used in
your application. It also contains few other subfolders:
drawable-<resolution>, layout, and values.
• AndroidManifest.xml — This is the manifest file for
your Android application. Here you specify the
permissions needed by your application, as well as
other features (such as intent-filters, receivers, etc.).
• The main.xml file defines the user interface(UI) for
your activity.
• The strings.xml file contain the string, exists in
res/values folder.
• Eclipse will automatically generate the content of
R.java, not supposed to modify the content of the
R.java file.
Android Manifest.xml
Android Manifest.xml
• It defines the package name of the application as net.learn2develop.HelloWorld.
• The version code of the application is 1 (set via the android:versionCode
attribute). This value is used to identify the version number of your application. It
can be used to programmatically determine whether an application needs to be
upgraded.
• The version name of the application is 1.0 (set via the android:versionName
attribute). This string value is mainly used for display to the user. You should use
the format <major>.<minor>.<point> for this value.
• The android:minSdkVersion attribute of the <uses-sdk> element specifies the
minimum version of the OS on which the application will run.
• The application uses the image named ic_launcher.png located in the drawable
folders.
• The name of this application is the string named app_name defined in the
strings.xml file.
• There is one activity in the application represented by the
HelloWorldActivity.java file. The label displayed for this activity is the same as the
application name.
• Within the definition for this activity, there is an element named <intent-filter>
R.java
• Eclipse will automatically generate the content of R.java
activity_hello_world_app.xml
• <RelativeLayout #1
xmlns:android="http://schemas.android.com/apk/res/android"
#2
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" #3
android:layout_height="match_parent">
<TextView #4
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello" #5
tools:context=".HelloWorldAppActivity" />
</RelativeLayout>

The match_parent value in statement #3 tells the Android system to fill as much
space as possible on the screen based on the available space of the parent layout.
The wrap_content value tells the Android system to take up only as much space as
needed to show the View.
HelloWorldAppActivity.java
• package com.androidunleashed.helloworldapp;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class HelloWorldAppActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) { #1
super.onCreate(savedInstanceState); #2
setContentView(R.layout.activity_hello_world_app); #3
}
@Override
public boolean onCreateOptionsMenu(Menu menu) { #4
getMenuInflater().inflate(R.menu.activity_hello_world_app, menu);
return true;
}
}
In statement #1, the parameter Bundle savedInstanceState refers
to a bundle used to pass information between different
activities.

Statement #2 is essential for activity initialization. If you


don’t write this statement into the Java file, you get a
runtime exception.

Statement #3 defines the screen (user interface) of the


activity HelloWorldAppActivity.
Run configuration—Used to run an application on a given device
Debug configuration—Used to debug an application while it’s
running on a given device
USING THE TEXTVIEW CONTROL
• In android ui or input controls are the interactive
or View components which are used to design
the user interface of an application.
• In android we have a wide variety of UI or input
controls available, those are TextView, EditText,
Buttons, Checkbox, Progressbar, Spinners, etc.
• In android, TextView is a user interface control
which is used to set and display the text to the
user based on our requirements.
• The TextView control will act as like label control
and it won’t allow users to edit the text.
USING THE TEXTVIEW CONTROL
• In android, we can create a TextView
control in two ways –
– either in XML layout file or
– create it in Activity file programmatically.
res/layout/activity_main.xml file

<TextView
android:id="@+id/text_id"
android:layout_width="300dp"
android:layout_height="200dp"
android:capitalize="characters"
android:text="hello_world"
android:textColor="@android:color/holo_blue_dark"
android:textColorHighlight="@android:color/primary_te
xt_dark" android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:textSize="50dp"/>
src/com.example.demo/MainActivity.java

public class MainActivity extends Activity {


@Override protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RelativeLayout relativeLayout = (RelativeLayout)
findViewById(R.id.rootlayout);
TextView textView = new TextView(this);
textView.setText("Hey, one more TextView");
relativeLayout.addView(textView); } }
Dimensions
• Dimensions are commonly used to specify the size and other
properties for the controls and layouts. The following units of
measurements are used:
• px (pixels)—Corresponds to the actual pixels on the screen.
• in (inches)—Based on the actual size of the screen.
• mm (millimeters)—Based on actual size of the screen.
• pts (points)—Points are a fixed dimension—1/72 of an inch.
• dip or dp (device-independent pixels)—Based on the physical
density of the screen. This unit is relative to a 160 dpi screen, so
one dp is one pixel on a 160 dpi screen. The ratio of dp to pixel
changes with the screen density. For example, on a 240
dpi screen, 1 dp is equal to 1.5 pixels.
• sp (scale independent pixels)—Similar to the dp unit, but also
depends on the user’s font size settings. Hence this unit is preferred
while specifying font sizes.
USING THE ANDROID EMULATOR
• The Android emulator is used for testing and
debugging applications before they are loaded onto a
real handset.
• Android emulator is typically used for deploying apps
that are developed in IDE without actually installing it
in a device.
• Android emulators such as Bluestacks can run
android apps where in which emulators like AVD and
genymotion are used to emulate an entire operating
system.
• The Android emulator is integrated into Eclipse
through the ADT plug-in.
Limitations of the Android Emulator
• don’t provide the actual environment (memory, CPU,
or other physical limitations ) to an application.
• Emulators just simulate certain handset behavior.
• SMS messages are also simulated and do not use a
real network.
• Phone calls cannot be placed or received but are
simulated.
• No support for device-attached headphones is
available.
• Peripherals such as camera/video capture are not
fully functional.
• No USB or Bluetooth support is available.
• specific emulator commands. Some of the most commonly
used commands are
• Back [ESC button]
• Call [F3]
• End [F4]
• Volume Up [KEYPAD_PLUS, Ctrl-5]
• Volume down [KEYPAD_MINUS, Ctrl-F6]
• Switching orientations [KEYPAD_7, Ctrl-F11/KEYPAD_9,
Ctrl-F12]
• You can also interact with an emulator from within the
DDMS tool.
• Eclipse IDE provides three perspectives to work with:
– Java perspective,
– Debug perspective, and
– DDMS perspective.
• The Java perspective
– It’s the default perspective in Eclipse where you spend
most of the time. It shows the panes where you can
write code and navigate around the project.
• The Debug perspective
– Enables application debugging. You can set
breakpoints; step through the code; view LogCat
logging information, threads, and so on.
• The Dalvik Debug Monitor Service (DDMS)
perspective
– Enables you to monitor and manipulate emulator and
device status. It also provides screen capture and
simulates incoming phone calls, SMS sending, and
GPS coordinates.
DDMS
• The Dalvik Debug Monitor Service (DDMS) is a debugging
tool used in the Android platform.
• The Dalvik Debug Monitor Service is downloaded as part of
the Android SDK.
• Some of the services provided by the DDMS are port
forwarding, on-device screen capture, on-device thread
and heap monitoring, and radio state information.
• The Dalvik Debug Monitor Service allows developers to
spot bugs in applications running on either an emulator or
an actual Android device.
• For example, by using the DDMS’ LogCat feature,
developers can view log messages regarding the state of
the application and the device. LogCat can pinpoint the
exact line number on which an error occurred.
DDMS
• Another DDMS feature, known as the Emulator
Control, allows developers to simulate phone
states and activities.
• For example, it can simulate different types of
networks such as GPRS, EDGE, and UTMS, which
can have different network characteristics such as
speed and latency.
• This debugging tool can be integrated into the
Eclipse IDE by adding the ADT (Android
Development Tools) plug-in.
gradle
• Gradle is a build system (open source) which is used
to automate building, testing, deployment etc.
• Every Android project needs a gradle for generating
an apk from the .java and .xml files in the project.
• Simply put, a gradle takes all the source files (java and
XML) and apply appropriate tools, e.g., converts the
java files into dex files and compresses all of them
into a single file known as apk that is actually used.
• There are two types of build.gradle scripts
– Top-level build.gradle
– Module-level build.gradle
THE ANDROID DEBUG BRIDGE(ADB)

• The Android-Debug-Bridge (abbreviated as adb) is a


software-interface for the android system, which can be
used to connect an android device with a computer using
an USB cable or a wireless connection.
• It can be used to execute commands on the phone or
transfer data between the device and the computer.
• It is a command line tool that is used to communicate
with a smartphone, tablet, smartwatch, set-top box, or
any other device that can run the Android operating
system (even an emulator).
THE ANDROID DEBUG BRIDGE(ADB)
• Since ADB is a client-server program, there are three
components that make up the entire process.
1. Client, the computer you have connected to your
Android device. It’s from this computer that we are
sending commands to our device through the USB cable
(or wirelessly).
2. The daemon (background process) (also known as adbd
– adb deamon), and this is a service that is currently
running on both the computer as well as the Android
device and allows the latter to accept and execute
commands.
3. Server, this is a piece of software that actually manages
the communication between the client and the
daemon.
Install ADB – Phone Setup
Phone Setup
• Launch the Settings application on your phone.
• Tap the About Phone option generally near the bottom of
the list (this is hidden behind the “System” option in
Google’s latest Android Oreo version).
• Then tap the Build Number option 7 times to enable
Developer Mode. You will see a toast message when it is
done.
• Now go back to the main Settings screen and you should
see a new Developer Options menu you can access.
• Go in there and enable the USB Debugging option.
• You are partially done with the phone setup process. Next
up, you will need to scroll below and follow the rest of the
instructions for your particular operating system.
Microsoft Windows ADB Setup
1. Download the ADB ZIP file for Windows
2. Extract the contents of this ZIP file into an easily accessible folder (such as
C:\adb)
3. Open Windows Explorer and browse to where you extracted the contents of
this ZIP file
4. Then open up a Command Prompt from the same directory as this ADB
binary. This can be done by holding Shift and Right-clicking within the folder
then click the “open command prompt here” option.
5. Connect your smartphone or tablet to your computer with a USB cable.
Change the USB mode to “file transfer (MTP-Media Transfer Protocol)” mode.
Some OEM(original equipment manufacturer)s may or may not require this,
but it’s best to just leave it in this mode for general compatibility.
6. In the Command Prompt window, enter the following command to launch the
ADB daemon: adb devices
7. On your phone’s screen, you should see a prompt to allow or deny USB
Debugging access. Naturally, you will want to grant USB Debugging access
when prompted (and tap the always allow check box if you never want to see
that prompt again).
8. Finally, re-enter the command from step #6. If everything was successful, you
should now see your device’s serial number in the command prompt.
Launching Android Applications on a Handset
• In Eclipse, choose the Run, Debug Configurations option.
• Select the configuration HelloWorldApp_configuration, which you
created for the HelloWorldApp application.
• Select the Target tab, set the Deployment Target Selection Mode
to Manual. The Manual option allows us to choose the device or
AVD to connect to when using this launch configuration.
• Apply the changes to the configuration file by clicking the Apply
button.
• Plug an Android device into your computer, using a USB cable.
• Select Run, Debug in Eclipse or press the F11 key. A dialog box
appears, showing all available configurations for running and
debugging your application. The physical device(s) connected to
the computer are also listed. Double-click the running Android
device.
• Eclipse now installs the Android application on the handset,
attaches a debugger, and runs the application.
need to install the USB driver for your
device.
The 'Android Device Chooser' will open. If you've connected your
device successfully, it will be listed under 'Choose a running Android
device.' Select your device and click 'OK.'
Session Outcome

End of today session:


Student can be able to write simple
android applications and deploy in
AVD

RCEW, Pasupula (V), Nandikotkur Road,


Near Venkayapalli, KURNOOL

You might also like