0% found this document useful (0 votes)
5 views

JFDP - Android App Developement Using Java PPT2

Uploaded by

sreenu_pes
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

JFDP - Android App Developement Using Java PPT2

Uploaded by

sreenu_pes
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Android Application

Development
Developed by Abhishek Bhargava
Introduction
•Welcome to world of Android Application Development!
•Android was acquired by Google in 2005 (yes, Android was a start-up company at
one point),
•This was to ensure that a mobile operating system (OS) could be created and
maintained in an open platform.
•Google continues to pump time and resources into the Android project, which has
already proved to be beneficial.
•As of July 2010, 160,000 Android handsets have been activated daily, which is
good considering that handsets have been available only since October 2008.
•That’s less than two years, and Android has already made a huge impact!
•It has never been easier for a developer to be able to make money on his own.
•Android users may not know who you are, but they know what Google is, and they
trust Google. Because your app resides in the Android Market — which Google
controls — Google assumes that your application is okay too.
Definition of android.
 Android is a Operating System for mobile devices
 It includes an basic in-built features, middleware and key applications.
 The Android SDK provides the tools and APIs necessary to begin
developing applications on the Android platform using the Java
programming language.
Features of android
 Application framework enabling reuse and replacement of components
 Dalvik virtual machine optimized for mobile devices
 Integrated browser based on the open source WebKit engine
 Optimized graphics powered by a custom 2D graphics library; 3D
graphics based on the OpenGL ES 1.0 specification (hardware acceleration
optional)
 SQLite for structured data storage
 Media support for common audio, video, and still image formats (MPEG4,
H.264, MP3, AAC, AMR, JPG, PNG, GIF)
 GSM Telephony (hardware dependent)
 Bluetooth, EDGE, 3G, and WiFi (hardware dependent)
 Camera, GPS, compass, and accelerometer (hardware dependent)
 Rich development environment including a device emulator, tools for
debugging, memory and performance profiling, and a plugin for the Eclipse IDE
Open platform
•The Android operating system is open platform, meaning that it’s not tied to one
hardware manufacturer and/or one provider.
•As you can imagine, the openness of Android is allowing it to gain market share
quickly.
•All hardware manufacturers and providers can make and sell Android devices.
•The Android source code is available at http://source.android.com for you to
view and/or modify.
•Nothing is holding you back from digging into the source code to see how a
certain task is handled.
•The open-source code allows phone manufacturers to create custom user
interfaces (UIs) and add built-in features to some devices.
•This also puts all developers on an even playing field. Everyone can access the
raw Android source code.
Cross-compatibility & Mash-up capability
Android can run on many devices with different screen sizes and resolutions.
Besides being cross-compatible, Android comes with the tools that help you
develop cross-compatible applications. Google allows your apps to run only
on compatible devices. If your app requires a front-facing camera, for example,
only phones with a front-facing camera will be able to see your app in the
Android Market. This arrangement is known as feature detection.

A mash-up combines two or more services to create an application. You can


create a mash-up by using the camera and Android’s location services, for
example, to take a picture with the exact location displayed on the image!
It’s easy to make a ton of apps by combining services or libraries in new and
exciting ways.
Architecture of android.
Applications
 Android will ship with a set of core applications including an email client, SMS program, calendar,
maps, browser, contacts, and others. All applications are written using the Java programming
language.
Application Framework
 By providing an open development platform, Android offers developers the ability to build
extremely rich and innovative applications. Developers are free to take advantage of the device
hardware, access location information, run background services, set alarms, add notifications to the
status bar, and much, much more.
 Developers have full access to the same framework APIs used by the core applications. The
application architecture is designed to simplify the reuse of components; any application can publish
its capabilities and any other application may then make use of those capabilities This same
mechanism allows components to be replaced by the user.
Underlying all applications is a set of services and systems, including:
 A rich and extensible set of Views that can be used to build an application, including lists, grids, text
boxes, buttons, and even an embeddable web browser
 An Activity Manager that manages the lifecycle of applications and provides a common navigation
backstack.
Libraries
 Android includes a set of C/C++ libraries used by various components of the Android
system. These capabilities are exposed to developers through the Android application
framework. Some of the core libraries are listed below:
 System C library - a BSD-derived implementation of the standard C system library
(libc), tuned for embedded Linux-based devices
 Media Libraries - based on PacketVideo's OpenCORE; the libraries support playback
and recording of many popular audio and video formats, as well as static image files,
including MPEG4, H.264, MP3, AAC, AMR, JPG, and PNG
 LibWebCore - a modern web browser engine which powers both the Android browser
and an embeddable web view
 3D libraries - an implementation based on OpenGL ES 1.0 APIs; the libraries use
either hardware 3D acceleration (where available) or the included, highly optimized
3D software rasterizer
 SQLite - a powerful and lightweight relational database engine available to all
applications
Android Runtime
 Android includes a set of core libraries that provides most of the functionality available
in the core libraries of the Java programming language.
 Every Android application runs in its own process, with its own instance of the Dalvik
virtual machine. Dalvik has been written so that a device can run multiple VMs efficiently.
The Dalvik VM executes files in the Dalvik Executable (.dex) format which is optimized
for minimal memory footprint. The VM is register-based, and runs classes compiled by a
Java language compiler that have been transformed into the .dex format by the included
"dx" tool.
 The Dalvik VM relies on the Linux kernel for underlying functionality such as threading
and low-level memory management.
Linux Kernel
 Android relies on Linux version 2.6 for core system services such as security, memory
management, process management, network stack, and driver model. The kernel also acts
as an abstraction layer between the hardware and the rest of the software stack.
Introduction to JAVA.
What is Java?
 Android applications are developed using the Java language. Java is a very
popular programming language developed by Sun Microsystems (now owned
by Oracle). Developed long after C and C++, Java incorporates many of the
powerful features of those powerful languages while addressing some of their
drawbacks.
Some of the Java’s important core features are:
 It’s designed to be platform-independent and secure, using
virtual machines
 It’s object-oriented
 Android relies heavily on these Java fundamentals. The Android SDK includes
many standard Java libraries (data structure libraries, math libraries, graphics
libraries, networking libraries and everything else you could want) as well as
special Android libraries that will help you develop awesome Android
applications.
Different accesses specifier
Class Permissions and Access
 You can control the visibility of a class as well as its variables and methods by
specifying an item’s access level.
 The access levels are: public, protected and private. Generally speaking, if you
want something to be accessible from outside a class, use public.
For example, the following SillySensor class definition defines several variables and
methods with different access levels:
A class variable called sensorData, which is only visible within the class
A public constructor that can be called outside the class
A private method called calibrate(), which can only be called from within the class
itself
A protected method called seedCalibration(), which can be called from within the
class itself, or by a subclass
A public method called getSensorData(), which can be called from anywhere,
allowing for “read-only” access to the sensorData variable
public class SillySensor protected void seedCalibration(int iSeed)
{ {
calibrate(iSeed);
private int sensorData; }

public SillySensor() public int getSensorData()


{
{ // Check sensor here
sensorData=0;
} return sensorData;
}

private void calibrate(int iSeed) }


{
// Do some calibration here
}
Now that wasn't difficult… or
was it?
Its just the beginning. Wake
up!
Using of ‘ this ‘ function
Using this with a Constructor
From within a constructor, we can also use the this keyword to call another constructor in the
same class.
public class Rectangle
{ private int x, y; private int width, height;
public Rectangle()
{ this(0, 0, 0, 0); }
public Rectangle(int width, int height)
{ this(0, 0, width, height); }
public Rectangle(int x, int y, int width, int height)
{ this.x = x;
this.y = y;
this.width = width;
this.height = height; } ... }
 This class contains a set of constructors. Each constructor initializes some or all of the
rectangle's member variables. The constructors provide a default value for any
member variable whose initial value is not provided by an argument. For example,
the no-argument constructor calls the four-argument constructor with four 0 values
and the two-argument constructor calls the four-argument constructor with two 0
values. As before, the compiler determines which constructor to call, based on the
number and the type of arguments.
Using of ‘ static ‘ function
 A static method can be accessed without creating an instance of the class. If you try to use a non-
static method and variable defined in this class then the compiler will say that non-static variable or
method cannot be referenced from a static context. Static method can call only other static methods
and static variables defined in the class.
 The concept of static method will get more clear after this program. First of all create a class
HowToAccessStaticMethod. Now define two variables in it, one is instance variable and other is
class variable. Make one static method named staticMethod() and second named as
nonStaticMethod(). Now try to call both the method without constructing a object of the class. You
will find that only static method can be called this way.
Eg: public class HowToAccessStaticMethod{
int i; static int j;
public static void staticMethod(){
System.out.println("you can access a static method this way"); }
public void nonStaticMethod(){
i=100; j=1000;
System.out.println("Don't try to access a non static method"); }
public static void main(String[] args) {
//i=100; j=1000;
//nonStaticMethod(); staticMethod(); }}
Debugging
 The Android SDK provides most of the tools that you need to debug your
applications. You need a JDWP-compliant debugger if you want to be able to do
things such as step through code, view variable values, and pause execution of an
application. If you are using Eclipse, a JDWP-compliant debugger is already
included and there is no setup required. If you are using another IDE, you can use
the debugger that comes with it and attach the debugger to a special port so it can
communicate with the application VMs on your devices. The main components that
comprise a typical Android debugging environment are:
 Adb adb acts as a middleman between a device and your development system. It
provides various device management capabilities, including moving and syncing files
to the emulator, running a UNIX shell on the device or emulator, and providing a
general means to communicate with connected emulators and devices.
 Dalvik Debug Monitor Server DDMS is a graphical program that communicates
with your devices through adb. DDMS can capture screenshots, gather thread and
stack information, spoof incoming calls and SMS messages, and has many other
features.
 Device or Android Virtual Device Your application must run in a device or in an
AVD so that it can be debugged. An adb device daemon runs on the device or
emulator and provides a means for the adb host daemon to communicate with the
device or emulator.

 JDWP debugger The Dalvik VM (Virtual Machine) supports the JDWP protocol to
allow debuggers to attach to a VM. Each application runs in a VM and exposes a
unique port that you can attach a debugger to via DDMS. If you want to debug
multiple applications, attaching to each port might become tedious, so DDMS
provides a port forwarding feature that can forward a specific VM's debugging
port to port 8700. You can switch freely from application to application by
highlighting it in the Devices tab of DDMS. DDMS forwards the appropriate port to
port 8700. Most modern Java IDEs include a JDWP debugger, or you can use a
command line debugger such as jdb.
Debugging Environment
 Figure 1 shows how the various debugging tools work together in a typical debugging
environment.
ERRORS:-

 Compile time error is any type of error that prevent a java program
compile like a syntax error, a class not found, a bad file name for the
defined class, a possible loss of precision when you are mixing different
java data types and so on.

 A runtime error means an error which happens, while the program is running.
To deal with this kind of errors java define Exceptions. Exceptions are
objects represents an abnormal condition in the flow of the program. It can
be either checked or unchecked.

You might also like