Mad Notes Jkuat
Mad Notes Jkuat
UNIT -I
INTRODUCTION
Mobile phones have changed the way we live our lives providing voice calling, text messaging and
mobile Internet access. The very first mobile phones were two-way radios that allowed taxi drivers
and the emergency Services to communicate. Motorola, on 3 April 1973 was first company to mass
produce the first handheld Mobile phone.
PRE-STANDARDISATION OF “0 G”
AT&T was one of the first to commercialize mobile telecommunication in 1947. The service known
simply as ―Mobile Telephone Service‖ (MTS) spread to more than a hundred towns and highway
paths by the end of the Year. The service relied on an operator to connect both incoming and
outgoing calls. The first generation of cellular networks paved the way to the networks. Use of
multiple cell tower sites, each Connected through a network, allowed users to travel and even
switch cell towers during a call. It was a Revolution built on existing, analog technology with the first
being built in Chicago in 1977. Known as the Analog Mobile Phone System (AMPS), it was built by
AT&T and it took FCC 11 years to approve AT&T’s Initial proposal in 1971. Advancement by 2G was
the introduction of SMS messaging, with the first computer generated SMS sent in 1992 in the UK.
The very first download services were also introduced using 2G technology and enabled users To
download ringtones. Mobile phones also saw use as another method of payment for services like car
parking In Finland and vending machines.
3G transformed the mobile phone industry and enabled widespread mobile Internet and the
transmission Services like TV and Radio for the very first time. Handset manufacturers jumped on
the bandwagon and Smartphone use took off. IP networks, bringing mobile Internet more in-line
with wired home Internet connections. Speed is of course the Big advantage. The fourth generation
of mobile communication is still evolving, and we’re bound to see new Standards, speed increases
and coverage benefits in the next few years. Mobile phones are used widely in our day-to-day lives
giving us the freedom to communicate anywhere and at Anytime. The latest mobile phones are
incorporated with features like MP3 players, high resolution camera, high Sound quality, 3G
technology and the list goes on.
Mobile Ecosystem is a collection of multiple device (mobile phones, Tablet, Phablet etc), software
(operating System, development tools, testing tools etc), Companies(device manufacturers, carrier,
apps stores, Development/testing companies) and the process by Which data (sms, bank-
transactions etc.) is transferred/Shared by a user from one device to another device or by the Device
itself based on some programs. Data (Text, Multi-media, and VOICE) sharing can be done between
devices of the same operating system or Different operating systems. Examples – Iphone (IOS) to
Windows Phone, Iphone IOS to Nexus(Android), Motorola(Android) to Nexus(Android).
The mobile phone allows us to connect to other compatible devices, surf the internet, listen to music, play games and
capture our precious moments. These latest mobile phones are stylish in looks and excellent in terms of usability and
functions. The 3G phones allow doing video calling and video conferencing. These phones allow fast data exchange
and information apart from faster data downloads via internet. MMS, SMS, Email client and instant messaging as well
as multimedia capabilities, gaming etc; are added features of latest mobile phones.
Native apps are built for a specific operating system. A native app developed for iOS operating system won’t
work on Android devices and vice-versa. If an app is developed for iOS, it will remain exclusive to that
operating system. Softwares' used to develop native apps generally would be Objective-C or Swift for iOS, Java
and ADT for Android operating system and .NET(C#) for Windows operating system.
Mobile web apps are the web applications to render/deliver pages on web browsers running in mobile devices.
Since these apps target browsers, they work on different mobile operating systems. You can view a mobile web
app on Android, iOS or Windows tablets and phone devices. They also work on PC web browsers. Softwares'
used to develop these applications are generally HTML, CSS, JavaScript, JQuery.
Hybrid apps are a mixture of both native and mobile web apps. This type of application has cross-platform
compatibility but can still access phone’s hardware. Softwares used to develop these apps are generally HTML,
CSS, Javascript, JQuery, Mobile Javascript frameworks, Cordova/PhoneGap etc.
Mobile Design
Small Screens
Decision needs to be made early as to whether to use responsive design (where the device handles the changes
in display) or adaptive design (where your servers handle the changes). A good process to follow would be:
Group device types based on similar screen sizes and try to keep this to a manageable number of
groups
Define content rules and design adaption rules that enable you to display things well on each group of
devices
Try to adhere as closely to web standards (W3) as possible when implementing flexible layouts
Don’t forget that there are many different browser types available for the mobile web and the wider
Internet too.
Prioritize navigation based on the way users work with functionality – the most popular go at the top
Minimize the levels of navigation involved
Ensure labelling is clear and concise for navigation
Offer short-key access to different features
Remember to offer a 30x30 pixel space for touch screen tap points
Ensure that links are visually distinct and make it clear when they have been activated too
Make it easy to swap between the mobile and full site (if you choose to implement separate versions)
Don’t overwhelm your users – respect the small screen space. Keep content to a minimum.
Make sure that content is universally supported on all devices or avoid it. Think Flash and then don’t
use it, for example.
Make page descriptions short and to the point – for relevant bookmarks.
Mobile connections can be a colossal PITA in areas with patchy service. Try:
Mobile 2.0
Mobile 2.0 refers to services that integrate the social web with the core aspects of mobility – personal, localized,
always-on and ever-present. A range of sites are available for both so-called "smartphones" and for more
ordinary "feature" mobile phones. Ex: Micro-blogging services - Jaiku, Twitter, Pownce, CellSpin; Open
platforms for sms services - Fortumo and Sepomo; Information providing and services - mobeedo.
Adobe Dreamweaver : Since the CS5.5 version, Dreamweaver has worked better with mobile markup and
allows us to validate against mobile web standards. When we create a new document we can choose HTML5
as the document type.
Adobe Edge Tools : Adobe offers a group of tools under the name of Edge that help designers and
developers to create HTML5 applications such as Edge Code, Edge Reflow, Edge Inspect, and Edge .
Microsoft Visual Studio and WebMatrix : Microsoft IDEs have supported HTML5 syntax and IntelliSense
since version 2010 SP1. WebMatrix for mobile web development is available for free.
Eclipse : To use Eclipse as our development environment, there are several plug-ins you can use to create
mobile HTML5 apps. Aptana from Titanium, a free Eclipse-based IDE for HTML5 and mobile development
can be downloaded as a free version from Aptana’s website.
Native Web IDEs : To target native web or hybrid apps, some platforms offer tools and IDEs that can be used
to develop, test, and build the final packages.
.
Testing : Emulators are very useful and provide a simple, fast, and fairly accurate testing solution. If it doesn’t
work in the emulator, it probably will not work on the real device.
A simulator is a less complex application that simulates some of the behavior of a device, but does not emulate
hardware and does not work over the real operating system. A simulator may be created by the device
manufacturer or by some other company offering a simulation environment for developers. In mobile browsing,
there are simulators with pixel-level simulation, and others that neither create a skin over a typical desktop
browser (such as Firefox, Chrome, or Safari) with real typography nor simulate these browsers’ rendering
engines.
For mobile web development, we will find emulators from Nokia, BlackBerry, Android, webOS, and Windows
Phone, and simulators from Apple for iOS (though only for Mac OS X). A multiple mobile browser simulator is
available from Adobe, called Device Central.
There are minimum resource requirements for a small computing device to run a J2ME application. First the
device must have a minimum of 96 × 54 pixel display that can handle bitmapped graphics and have a way for
users to input information, such as a keypad, keyboard, or touch screen. At least 128 kilobytes (KB) of
nonvolatile memory is necessary to run Mobile Information Device (MID), and 8KB of nonvolatile memory is
needed for storage of persistent application data.
To run JVM, 32KB of volatile memory must be available. The device must also provide two-way network
connectivity. The native operating system must implement exception handling, process interrupts, be able to run
the JVM, and provide schedule capabilities. Furthermore, all user input to the operating system must be
forwarded to the JVM, otherwise the device cannot run a J2ME application.
J2ME OVERVIEW
the Java development team enhanced the capabilities of Java to dramatically reduce the complexity of
developing a multi-tier application.
The team grouped features of Java into three editions, each having a software development kit (SDK).
The original edition of Java, called the Java 2 Standard Edition (J2SE), consists of application programming
interfaces (APIs) needed to build a Java application or applet.
The Java 2 Micro Edition (J2ME) contains the API used to create applications for small computing devices,
including wireless Java applications.
The development team at Sun worked on Java in the early 1990s to address the programming needs of the
fledgling embedded computer market, but that effort was sidetracked by more compelling opportunities
presented by the Internet.
As those opportunities were addressed, a new breed of portable communications devices opened other
opportunities at the turn of the century. Cell phones expanded from voice communications devices to voice and
text communications devices.
Pocket electronic telephone directories evolved into personal digital assistants. Chipmakers were releasing
new products at this time that were designed to transfer computing power from a desktop computer into mobile
small computers that controlled gas pumps, cable television boxes, and an assortment of other appliances.
J2ME is a reduced version of the Java API and Java Virtual Machine that is designed to operate within the
sparse resources available in the new breed of embedded computers and microcomputers.
Inside J2ME
Consumers expect the same software and capabilities found on their desktop and laptop computers to be
available on their cell phones and personal digital assistants.
Developers seeking to build applications tha run on cell phones, personal digital assistants, and various
consumer and industrial appliances must strike a balance between a thick client and a thin client.
J2ME Architecture
The modular design of the J2ME architecture enables an application to be scaled based on constraints of a
small computing device. J2ME architecture consists of layers located above the native operating system,
collectively referred to as the Connected Limited Device Configuration (CLDC). The CLDC, which is installed
on top of the operating system, forms the run-time environment for small computing devices. The J2ME
architecture comprises three software layers (Figure 3-1). The first layer is the configuration layer that includes
the Java Virtual Machine (JVM), which directly interacts with the native operating system. The configuration
layer also handles interactions between the profile and the JVM. The second layer is the profile layer, which
consists of the minimum set of application programming interfaces (APIs) for the small computing device. The
third layer is the Mobile Information Device Profile (MIDP). The MIDP layer contains Java APIs for user
network connections, persistence storage, and the user interface. It also has access to CLDC libraries and MIDP
libraries.
A small computing device has two components supplied by the original equipment manufacturer (OEM).
These are classes and applications. OEM classes are used by the MIDP to access device-specific features such
as sending and receiving messages and accessing device-specific persistent data. OEM applications are
programs provided by the OEM, such as an address book.
Run-Time Environment
A MIDlet is defined with at least a single class that is derived from the javax .microedition.midlet.MIDlet
abstract class. Developers commonly bundle related MIDlets into a MIDlet suite, which is contained within the
same package and implemented simultaneously on a small computing device. All MIDlets within a MIDlet suite
are considered a group and must be installed and uninstalled as a group. Members of a MIDlet suite share
resources of the host environment and share the same instances of Java classes and run within the same JVM.
This means if three MIDlets from the same MIDlet suite run the same class, only one instance of the class is
created at a time in the Java Virtual Machine. A key benefit of the relationship among MIDlet suite members is
that they share the same data, including data in persistent storage such as user preferences.
Sharing data among MIDlets exposes each MIDlet to data errors caused by concurrent read/write access to
data. This risk is reduced by synchronization primitives on the MIDlet suite level that restrict access to volatile
data and persistent data. A MIDlet suite is installed, executed, and removed by the application manager running
on the device. The application manager also makes the Java archive (JAR) file and the Java application
descriptor (JAD) file available to members of the MIDlet suite.
All the files necessary to implement a MIDlet suite must be contained within a production package called a
Java archive (JAR) file. These files include MIDlet classes, graphic images (if required by a MIDlet), and the
manifest file. The manifest file contains a list of attributes and related definitions that are used by the application
manager to install the files contained in the JAR file onto the small computing device. Nine attributes are
defined in the manifest file; all but six of these attributes are optional.
The MIDlet-n attribute can contain three values that describe the MIDlet. A comma separates each value.
The first value is the name of the MIDlet, which is BestMIDlet. Next is an optional value that specifies the icon
that will be used with the MIDlet. In this example, BestMIDlet.png is the icon. The icon must be in the PNG
image format. And the last value for the MIDlet-n attribute is the MIDlet class name, which is Best.BestMIDlet.
The application manager uses the class name to load the MIDlet.
A JAD file is also used to provide the application manager with additional content information about the JAR
file to determine whether the MIDlet suite can be implemented on the device. AJAD file is similar to a manifest
in that both contain attributes that are name:value pairs. Name:value pairs can appear in any order within the
JAD file. There are five required system attributes for a JAD file:
MIDlet-Name
MIDlet-Version
MIDlet-Vendor
MIDlet-n
MIDlet-Jar-URL 18
A developer can include application attributes in a JAD file. An application attribute is a name:value pair
that contains a value unique to the application.
MIDlet Programming
Programming a MIDlet is similar to creating a J2SE application in that you define a class and related
methods. A MIDlet is a class that extends the MIDlet class and is the interface between application statements
and the run-time environment, which is controlled by the application manager. A MIDlet class must contain
three abstract methods that are called by the application manager to manage the life cycle of the MIDlet. These
abstract methods are startApp(), pauseApp(), and destroyApp().
Both the startApp() and pauseApp() methods are public and have no return value nor parameter list. The
destroyApp() method is also a public method without a return value. However, the destroyApp() method has a
boolean parameter that is set to true if the termination of the MIDlet is unconditional, and false if the MIDlet can
throw a MIDletStateChangeException telling the application manager that the MIDlet does not want to be
destroyed just yet. At the center of every MIDlet are the MIDP API classes used by the MIDlet to interact with
the user and handle data management. The data-handling MIDP API classes enable the developer to perform
four kinds of data routines: write and read persistent data, store data in data types, receive data from and send
data to a network, and interact with the small computing device’s input/output features.
Event Handling
A MIDlet is an event-based application. All routines executed in the MIDlet are invoked in response to an
event reported to the MIDlet by the application manager. The startApp() method in a typical MIDlet contains a
statement that displays a screen of data and prompts the user to enter a selection from among one or more
options. A Command object is used to present a user with a selection of options to choose from when a screen is
displayed. Each screen must have a CommandListener. A CommandListener monitors user events with a screen
and causes the appropriate code to execute based on the current event.
User Interfaces
The design of a user interface for a MIDlet depends on the restrictions of a small computing device. A rich
user interface contains the following elements, and a device with a minimal user interface has some subset of
these elements as determined by the profile used for the device. A Form is the most commonly invoked user
interface element found in a MIDlet and is used to contain other user interface elements. Text is placed on a
form as a StringItem, a List, a ChoiceGroup, and a Ticker. A StringItem contains text that appears on a form that
cannot be changed by the user. A List is an itemized options list from which the user can choose an option. A
ChoiceGroup is a related itemized options list. And a Ticker is text that is scrollable. A user enters information
into a form by using the Choice element, TextBox, TextField, or DateField elements. The Choice element
returns an option that the user selected. TextBox and TextField elements collect textual information from a user
and enable the user to edit information that appears in these user interface elements. The DateField is similar to a
TextBox and TextField except its contents are a date and time. An Alert is a special Form that is used to alert the
user that an error has occurred. An Alert is usually limited to a StringItem user interface element that defines the
nature of the error to the user.
Device Data
Small computing devices don’t have the resources necessary to run an onboard database management system
(DBMS). A MIDlet can use an MIDP class—RecordStore—and two MIDP interfaces— RecordComparator and
RecordFilter—to write and read persistent data. A RecordStore class contains methods used to write and read
persistent data in the form of a record. Persistent data is read from a RecordStore by using either the
RecordComparator interface or the RecordFilter interface.
The J2ME Wireless Toolkit is used to develop and test J2ME applications by selecting a few buttons from a
toolbar.
After downloading the J2ME Wireless Toolkit from the Sun web site, let’s create a new project by selecting the
New Project button from the toolbar. You’ll be prompted to enter a project name and class name. Enter Hello
World as the project name and greeting.HelloWorld as the class name, which is the name of the first MIDlet that
is associated with the project. After selecting the Create Project button, the J2ME Wireless Toolkit
automatically creates a directory structure for the project and also creates the manifest file and JAD file.
Enter the project name and class name of the first MIDlet to begin the project. P:\010Comp\CompRef8\710-
9\ch03.vp Thursday, February 06, 2003 11:40:19 AM Color profile: Generic CMYK printer profile Composite
Default screen Chapter 3: J2ME Architecture and Development Environment 63 Complete Reference / J2ME:
TCR / Keogh / 222710-9 / Chapter 3 J2ME BASICS.
A subdirectory of the apps directory is created for every project. And within the project’s subdirectory is
another set of subdirectories. These are ■ src, containing source code ■ bin, containing the manifest.mf file,
JAD file, and JAR file Figure 3-10. List of optional attributes P:\010Comp\CompRef8\710-9\ch03.vp Thursday,
February 06, 2003 11:40:20 AM Color profile: Generic CMYK printer profile Composite Default screen ■
classes, containing the compiled classes ■ tmpclasses, containing the preverify classes ■ res, containing image,
data, and other files required by the application.
create the first MIDlet once the Java development kit, Connected Limited Device Configuration (CLDC),
and Mobile Information Device Profile (MIDP) are installed.
Lets begin by creating a directory structure within which you can create and run MIDlets. Lets create the
HelloWorld MIDlet now. Enter the code shown in Listing 3-4 into a text editor such as Notepad, and save the
file in the j2me\src\greeting directory as HelloWorld.java.
The HelloWorld MIDlet performs three basic functions that are found in nearly all MIDlets. These are to
display a text box and a command on the screen, then listen to events that occur while the MIDlet is running.
The HelloWorld MIDlet is created by defining a class called HelloWorld that extends the MIDlet class and
implements a CommandListener. The HelloWorld class contains three private data members and four methods.
the final statement within the startApp() method associates the TextBox object with the Display object by
calling the setCurrent() method of the Display object and passing the setCurrent() method the TextBox object.
Prior to invoking the notifyDestroyed() method, a MIDlet should have completed its own garbage collection.
The Hello World source code files should be saved in the new j2me\src\greeting directory as
HelloWorld.java. The first step is to use the Java compiler to transform the source file into a class file. The
second step is to preverify the class file. The preverification generates a modified class file. Make
j2me\src\greeting the current directory, and then enter the following command at the command line. javac -d
d:\j2me\tmp_classes -target 1.1 -bootclasspath d:\j2me\midp1.0.3fcs\classes HelloWorld.java.
A MIDlet should be tested in an emulator before being downloaded to a small computing device. An
emulator is software that simulates how a MIDlet will run in a small computing device. There are two ways to
run a MIDlet. These are either by invoking the MIDlet class or by creating a JAR file, then running the MIDlet
from the JAR file. Click the right telephone handset icon to close the MIDlet. midp -classpath d:\j2me\classes
greeting.HelloWorld.
A MIDlet should be placed in a MIDlet suite after testing is completed. This suite is then packaged into a
JAR file along with other related files for downloading. This process is commonly referred to as packaging.
MIDlet-1: HelloWorld, , greeting.HelloWorld MIDlet-Name: Hello World MIDlet-Version: 1.0 MIDlet-
Vendor: Jim MIDlet-1: HelloWorld, /greeting/myLogo.png, greeting.HelloWorld MicroEdition-Configuration:
CLDC-1.0 MicroEdition-Profile: MIDP-1.0.
can create the JAR file once the manifest.txt file is saved in the j2me\src\ greeting directory. Make sure the
j2me\src\greeting directory is the current directory, and then create the JAR file by entering the following
command: jar -cfvm d:\j2me\midlets\HelloWorld.jar manifest.txt -C d:\j2me\classes greeting The final piece of
the Hello World package is a JAD file. save the JAD file in the j2me/src/greeting directory.
MIDlet-Name: Hello World MIDlet-Version: 1.0 MIDlet-Vendor: Jim, MIDlet-Description: My First MIDlet
suite MIDlet-1: HelloWorld, /greeting/myLogo.png, greeting.HelloWorld MIDlet-Jar-URL: HelloWorld.jar
MIDlet-Jar-Size: 1428. Copy the HelloWorld.jad file into the j2me/midlets directory, and then make
j2me/midlets the current directory. Click the right telephone handset icon to close the MIDlet. midp -classpath
HelloWorld.jar -Xdescriptor HelloWorld.jad.
In the real world, multiple MIDlets are distributed in a single MIDlet suite. The application manager
then displays each MIDlet as a menu option, enabling the user to run one of the MIDlets.
HISTORY OFANDROID
In October 2003, Android Inc was founded in Palo Alto, California and its four founders
were Rich Miner, Nick Sears, Chris White, and Andy Rubin. In 2005, Android was acquired
by Google. Rubin stayed at Google as head of the Android team until 2013.
The logo for the Android OS was created by Irina Blok while she was employed by Google.
ANDROID1.5 CUPCAKE
ANDROID1.6 DONUT
ANDROID2.0-2.1 ÉCLAIR
ANDROID2.2 FROYO
ANDROID2.3 GINGERBREAD
ANDROID3.0 HONEYCOMB
ANDROID4.0 ICECREAMSANDWICH
ANDROID4.1-4.3 JELLYBEAN
ANDROID4.4 KITKAT
ANDROID5.0 LOLLIPOP
ANDROID6.0 MARSHMALLOW
ANDROID7.0 NOUGAT
ANDROID8.0 OREO
ANDROID9.0 PIE
ANDROID10 Q
Android Q will allow users to control apps’ access to their phone’s Photos and Videos or the Audio collections
via new runtime permissions.
INTRODUCTION TO ANDROID
In 2007, Apple launched the first iPhone and ushered in a new era in mobile computing. In Sept. 2008, the very
first Android smartphone was announced, the T-Mobile G1 went on sale in the U.S. Oct. of that year.
Android 1.0 OS inside integrated a number of the company’s other products and services, including Google Maps,
YouTube, and an HTML browser (pre-Chrome) that, of course, used Google’s search services. It also had the first
version of Android Market, the app store with ―dozens of unique, first-of-a-kind Android applications.‖
The first version of the OS (1.0) released in Sept. 2008 did not have a code name at all. However, it reportedly
used the internal name ―Petit four‖ while it was in development at Google. The name refers to a French dessert.
Android has come a long way from its humble beginnings, as the
product of a small start up, all the way to becoming the leading
mobile operating system worldwide. Google’s introduction of Project
Treble in Android Oreo should make it easier for phone makers to
update their devices faster.
One challenge for Android device owners that has been an issue for
the OS ever since it launched is updating it with the latest security
patches, for major feature updates. Google’s supported Nexus and
Pixel devices consistently receive regular monthly security updates,
and the latest version of the OS.
OPERATING SYSTEMS
Different OS run on different types of hardware and are designed for different types of applications. For
example, iOS is designed for iPhones and iPad tablets, while Mac desktops and laptops use macOS.
Mobile Application Development Page | 10
MICROSOFT WINDOWS :
Initial versions of Windows worked with MS-DOS, providing a modern graphical interface on top of DOS's
traditional text-based commands. The Windows Start menu helps users find programs and files on their devices.
APPLE IOS
Apple's iOS is one of the most popular smartphone operating systems, second only to Android. It runs on Apple
hardware, including iPhones, iPad tablets and iPod Touch media players.
GOOGLE'S ANDROID OS
Android is the most popular operating system in the world judging by the number of devices installed. Users
can download custom versions of the operating system.
APPLE MAC OS
Apple's macOS, successor to the popular OS X operating system, runs on Apple laptops and desktops.. MacOS
is known for its user-friendly features, which include Siri and FaceTime.
LINUX OPERATING SYSTEM
Linux can be run on a wide variety of hardware and is available free of charge over the internet.
Android Studio – The official IDE, based on the community-created IntelliJIDEA (see below).
Eclipse – Before Android Studio, this was the official Android development environment. Used to
code Java but can be expanded to other languages via plugins, it is still a powerful tool.
IntelliJIDEA – Android Studio is based on this, and this IDE is not only extremely useful, but has a
massive amount of community-created plugins, making it highly customisable.
DroidEdit – An Android text and code editor to use on Android platforms.
Android-IDE – A complete web and Android development environment, it also allows you to edit Java
and PhoneGap apps.
Cordova – Mobile apps with HTML, CSS and JS, its one of the best tools if you want to create hybrid
apps. Free and open source.
Corona – A 2D-development platform with a specific focus on games but can be used to create other
types of mobile apps too. One of the best for cross-platform development and 100% free.
Titanium – One of the lesser-known platforms, it allows for the creation of native apps for iOS,
Android and Windowsphone and runs off a single JavaScript codebase.
Xamarin – Widely featured in the press and a very impressive IDE for native Android, iOS and
Windows applications. Open source and free with two further price plans, it uses C# as its language
CppDroid – Allows you to code, edit compile and execute C and C++ code. Packed full of features
including practice programs and syntax highlighting.
Java – Straight to the source, if you’re developing in Android, Java is probably the language you want
to be using. Has it’s own development kit, but there are plenty of other SDKs out there too.
Codeacademy – One of the premier code-learning resources online, it has been used by thousands of
people to get into Java coding, as well as other languages and frameworks. An interactive, learn-as-
you-code format.
Team treehouse – Another e-learning website, but well known for the strength of its Java courses.
Udemy – Online learning can’t go without mentioning Udemy, which features dozens of both highly
specific and generic Java learning courses.
New Boston – Youtube tutorials to learn how to develop in Android – currently has over 5 million
views. Covers everything from setting up the SDK to XLM Layouts. 200 videos in total.
Mobile Application Development Page | 11
Ryan Park Apps resource list – Ryan Parks taught himself how to code in Java and published, among
others, a personal finance application. This is the list of resources he used.
Oracle Java Tutorials – Both general and specialised Java tutorials by IT giants Oracle, starts from the
very basic concepts and overview.
Cave of Programming – Covers both Java and C++, comes with exercises and tests: also sometimes
offers paid-for courses for free, pending approval by the creator of the site, John.
Android Libraries
Android Plug-ins
Plugin collection for IntelliJ – The main repository for IntelliJ plugins, an absolute treasure-trove of
handy tools for the IntelliJ IDE.
A curated list of IntelliJ Plugins – The above repository is absolutely huge, so to help you get started
and find some gems, here’s a curated list of the best IntelliJ plugins.
Import Drawables – For IntelliJ, allows importing of drawables at different resolutions and other
image-based functionalities.
GenyMotion – One of the biggest and most reliable testing and emulation tools for Android apps –
employed by BlaBla Car among other high-profile names.
Boilerplate Code Generation – For IntelliJ, generates parcelable boilerplate code.
Android Holo Colors – Generates all necessary XML to have editext and colour spinners in your
Android app.
ANDROID ARCHITECTURE
Android offers a custom plugin for the Eclipse IDE, called Android Development Tools (ADT). This plugin
provides a powerful, integrated environment in which to develop Android apps. It extends the capabilities of
Eclipse to let you quickly set up new Android projects, build an app UI, debug your app, and export signed (or
unsigned) app packages (APKs) for distribution.
If you need to install Eclipse, you can download it from eclipse.org/mobile.
Note: If you prefer to work in a different IDE, you do not need to install Eclipse or ADT. Instead, you can
directly use the SDK tools to build and debug your application.
1. Once Eclipse restarts, you must specify the location of your Android SDK directory:
2. In the "Welcome to Android Development" window that appears, select Use existing SDKs.
3. Browse and select the location of the Android SDK directory you recently downloaded and unpacked.
4. Click Next.
5. Your Eclipse IDE is now set up to develop Android apps, but you need to add the latest SDK platform
tools and an Android platform to your environment. To get these packages for your SDK, continue to
Adding Platforms and Packages.
Troubleshooting Installation
1. If you are having trouble downloading the ADT plugin after following the steps above, here are some
suggestions:
2. If Eclipse can not find the remote update site containing the ADT plugin, try changing the remote site
URL to use http, rather than https. That is, set the Location for the remote site to:
3. http://dl-ssl.google.com/android/eclipse/
4. If you are behind a firewall (such as a corporate firewall), make sure that you have properly configured
your proxy settings in Eclipse. In Eclipse, you can configure proxy information from the main Eclipse
menu in Window (on Mac OS X, Eclipse) > Preferences > General > Network Connections.
If you are still unable to use Eclipse to download the ADT plugin as a remote update site, you can download the
ADT zip file to your local machine and manually install it:
1. Download the ADT Plugin zip file (do not unpack it):
To update your plugin once you've installed using the zip file, you will have to follow these steps again instead
of the default update instructions.
If you encounter this error when installing the ADT Plugin for Eclipse:
...then your development machine lacks a suitable Java VM. Installing Sun Java 6 will resolve this issue and you
can then reinstall the ADT Plugin.
Step 2: Click on new and enter a name and the operating system details for the virtual machine. Select
type as Linux and version as other and click next.
Step 3: Enter the amount of ram you would like to allot for the virtual machine and click next. Android 4.3
requires at least 1Gb of ram but its not necessary.
Step 4: In the next window select ― Create a virtual hard disk ― and then select VDI .
Step 6: Your virtual machine is now set . all you need to do is add the location of the Android 4.3 image
file . Click on the settings button in virtualbox . Under the settings navigate to storage , below the storage
tree select empty and click on the disk image and select ― choose a virtual CD/DVD disk file ― and
select the android 4.3 image . Check the Live CD/DVD box and click ok.
Step 7: Double click on your virtual machine to start it and click OK for all the dialog boxes . Select Install
Android-X86 to hard disk and click OK for all the dialog boxes .
Step 8: in the next window you have to create a partition for installing Android . The new partition will not
mess up anything with your windows computer . From now onwards you have to use your up , down , left
and right keys on your keyboard to Select ―create/modify partitions ― and click OK .
Step 9: In the next windows select new > primary and then specify the size of the new partition
Step 10: Your new partition has been created . Select write and press enter and type ―yes ― and press
enter again when prompted . In the next window select quit and press enter.
Step 11 : In the next window select the Sda1 and press enter. select the et3 file system and press enter .
When prompted to install grub loader select yes. Select now when prompted to make system directory as
read-write .
Step 12: Now android 4.3 is successfully installed on your virtual machine . select Run Android 4.3 and press
enter . click OK for any other dialog boxes that appear . You will now see the android loading screen .
Step 13: Select your language and enter , now fill in the Gmail details and all the details that are asked .
Step 14: Now We have successfully installed Android 4.3 on windows computer .
Inorder to uninstall the android 4.3 virtual box, right click on the virtual machine and select remove. Next select
―delete all files‖ to remove Android 4.3 completely from PC.
Using the Work with drop-down menu, select the Google ADT entry that you added in the previous step
Wait for the package list to be populated
Select all the resulting ADT packages
Click the Next button
Click the Next button on the Install Details screen that follows
Select each package in turn from the left-hand pane and accept the respective license agreement
Click the Finish button
Once the installation is complete, click the Restart Now button
Choose your preferred Titanium SDK version from the SDK Version drop-down list
Check the Android SDK / Target Android Platform section of the Titanium Compatibility Matrix, to
determine which Android versions are compatible with your chosen Titanium SDK. For example, Titanium
SDK 1.6.X is compatible with Android versions 1.6 to 2.3. This information will be needed for the
configuration in the following steps
Close tiapp.xml
Select DDMS (which stands for, Dalvik Debug Monitor Server) from the list of available perspectives
To ensure that the perspective is in its default state, select the Window > Reset Perspective... menu
Click the OK button, when the resulting Do you want to reset the current DDMS perspective to
its defaults?dialog displays
Now that the emulator is running, select it from the list of devices in the left-hand pane, and inspect it using
the tools
For example, select the File Explorer tab, and navigate to the directory /data/data/yourAppId
AppId was defined when the project was created, as shown in the TiApp Editor (see below)
8. Leave unchecked the Include Instant App support and all other options. Then click Next. If your
project requires additional components for your chosen target SDK, Android Studio will install them
automatically.
9. The Add an Activity window appears. An Activity is a single, focused thing that the user can do. It is
a crucial component of any Android app. An Activity typically has a layout associated with it that
defines how UI elements appear on a screen. Android Studio provides Activity templates to help you
get started. For the Hello World project, choose Empty Activity as shown below, and click Next.
10. The Configure Activity screen appears (which differs depending on which template you chose in the
previous step). By default, the empty Activity provided by the template is named MainActivity. You
can change this if you want, but this lesson uses MainActivity.
11. Make sure that the Generate Layout file option is checked. The layout name by default is
activity_main. You can change this if you want, but this lesson uses activity_main.
12. Make sure that the Backwards Compatibility (App Compat) option is checked. This ensures that
your app will be backwards-compatible with previous versions of Android.
13. Click Finish.
Android Studio creates a folder for your projects, and builds the project with Gradle.
The Android Studio editor appears. Follow these steps:
1. Click the activity_main.xml tab to see the layout editor.
2. Click the layout editor Design tab, if not already selected, to show a graphical rendition of the layout as
shown below.
3. Click the MainActivity.java tab to see the code editor as shown below.
The manifests folder contains files that provide essential information about your app to the Android system,
which the system must have before it can run any of the app's code.
1. Expand the manifests folder.
2. Open the AndroidManifest.xml file.
The AndroidManifest.xml file describes all of the components of your Android app. All components for an app,
such as each Activity, must be declared in this XML file. In other course lessons you will modify this file to add
features and feature permissions. For an introduction, see App Manifest Overview.
RUN ON EMULATOR
1. Lets create an android virtual device (avd). In order to run an emulator on your computer, you have to create a
configuration that describes the virtual device. In Android Studio, select Tools > Android > AVD Manager, or
click the AVD Manager icon in the toolbar. The Your Virtual Devices screen appears. If you've
already created virtual devices, the screen shows them; otherwise you see a blank list.
2. Click the +Create Virtual Device. The Select Hardware window appears showing a list of pre configured
hardware devices. For each device, the table provides a column for its diagonal display size (Size), screen
resolution in pixels (Resolution), and pixel density (Density).
3. Choose a device such as Nexus 5x or Pixel XL, and click Next. The System Image screen appears.
4. Click the Recommended tab if it is not already selected, and choose which version of the Android system to
run on the virtual device (such as Oreo).Click the link to start the download, and click Finish when it's done.
5. After choosing a system image, click Next. The Android Virtual Device (AVD) window appears. You can
also change the name of the AVD. Check your configuration and click Finish.
1. In Android Studio, choose Run > Run app or click the Run icon in the toolbar.
2. The Select Deployment Target window, under Available Virtual Devices, select the virtual
device, which you just created, and click OK
The emulator starts and boots just like a physical device. Your app builds, and once the emulator is ready,
Android Studio will upload the app to the emulator and run it.
In order to install an application directly to your device, you need to configure it to use a USB connection.
The configuration settings vary by device.
1. Open Settings.
2. Click Security.
3. Enable Unknown sources, that is, check this option. This permits the device to install apps that do
not originate from Google Play.
4. Back out to Settings.
5. Click Developer options.
6. If available: Set the switch in the title bar to on.
7. Enable USB debugging, that is, check this option. This permits the device to install apps over a
USB connection.
8. Optional: Enable Stay awake, that is, check this option. This option keeps the screen on and
disables the lock screen while the device is connected to USB.
9. Optional: Enable Allow mock locations, that is, check this option. This option creates fake GPS
locations to test location services.
10. Back out of or close Settings.
Developers on Windows may need to install a USB driver specific to the manufacturer and model of the
device on which they'll be testing. The driver enables your Windows computer to communicate with your
Android device. Google provides download links to the drivers at Android Developer: OEM USB Drivers.
Connect the Android device to your computer using an USB cord. Note that some USB cables are only
power cables and do not allow communications with the device. Make sure you use a USB cable that allows
a data connection.
For 4.2 devices, an "Allow USB debugging?" dialog will appear once connected via USB. Click the OK
button.
In Studio, first select the project in the Project Explorer view, then in the global tool bar, select Run from
the Launch Mode drop-down list and an Android device from the Target drop-down list under the Android
Application Installer category. If the Launch Automatically option is enabled under the Target drop-
down list, the application will be automatically launched after the device is selected. If not, you need to click
the Run button to start the build process. Your app will be built, installed to your device and automatically
launched.
APPLICATION CONTEXT
Application Context is It is an instance which is the singleton and can be accessed in an activity via
getApplicationContext(). This context is tied to the lifecycle of an application. The application context can be
used where you need a context whose lifecycle is separate from the current context or when you are passing a
context beyond the scope of an activity.
Activity Context
This context is available in an activity. This context is tied to the lifecycle of an activity. The activity context
should be used when you are passing the context in the scope of an activity or you need the context whose
lifecycle is attached to the current context.
getContext() in ContentProvider
This context is the application context and can be used similar to the application context. This can be accessed
via getContext() method.
INTENTS
Intent is a simple message object that is used to communicate between android components such as activities,
content providers, broadcast receivers and services. Intents are also used to transfer data between activities.
The implicit intent is the intent where instead of defining the exact components, you define the action that you
want to perform for different activities.An explicit intent is Intent where you explicitly define the component
that needs to be called by the Android System. An explicit intent is one that you can use to launch a specific app
component, such as a particular activity or service in your app.
ACTIVITY LIFECYCLE
Android Activity Lifecycle is controlled by 7 methods that describes how activity will behave at different states.
Android devices come in all shapes and sizes, so your app's layout needs to be flexible. That is, instead of
defining your layout with rigid dimensions that assume a certain screen size and aspect ratio, your layout should
gracefully respond to different screen sizes and orientations.
The best way to create a responsive layout for different screen sizes is to use Constraint Layout as the base
layout in your UI. Constraint Layout allows you to specify the position and size for each view according to
spatial relationships with other views in the layout. This way, all the views can move and stretch together as the
screen size changes.
The easiest way to build a layout with Constraint Layout is to use the Layout Editor in Android Studio. It allows
you to drag new views to the layout, attach their constraints to the parent view and other sibling views, and edit
the view's properties, all without editing any XML by hand.
FORM WIDGETS
Widgets enable users to interact with an Android Studio application page. There are various kinds of widgets,
such as Buttons and TextViews.
To see all the widgets at your disposal, create a new application project called ―Widgets‖ and select "empty
activity". Call your activity ―MainActivity‖.
There are two components of each Android activity: the XML (Extensible Markup Language) design (the
beauty) and the Java text (the brains).
On the activity_main.xml page, you can see the full widgets palette underneath the various layout options.
As you can see, there are 20 widgets available for you to use. In this guide, we’ll discuss TextViews and
Buttons, which are probably the most common widgets in Android development.
TEXT FIELDDS
A text field allows the user to type text into your app. It can be either single line or multi-line. Touching a text
field places the cursor and automatically displays the keyboard. In addition to typing, text fields allow for a
variety of other activities, such as text selection (cut, copy, paste) and data look-up via auto-completion.
You can add a text field to you layout with the EditText object. You should usually do so in your XML layout
with a <EditText> element.
Text fields can have different input types, such as number, date, password, or email address.
LAYOUTS
A layout defines the visual structure for a user interface, such as the UI for an activity or app widget. Each
layout has a set of attributes which define the visual properties of that layout. There are few common attributes
among all the layouts and there are other attributes which are specific to that layout. Following are common
attributes and will be applied to all the layouts.
BUTTON CONTROL
Button is a user interface control which is used to perform an action whenever the user click or tap on it.
Buttons in android will contains a text or an icon or both and perform an action when user touches it. Different
types of buttons available are ImageButton, ToggleButton, RadioButton.
A toggle button allows the user to change a setting between two states.
You can add a basic toggle button to your layout with the ToggleButton object. Android 4.0 (API level 14)
introduces another kind of toggle button called a switch that provides a slider control, which you can add with a
Switch object.SwitchCompat is a version of the Switch widget which runs on devices back to API 7.
Spinners provide a quick way to select one value from a set. In the default state, a spinner shows its currently
selected value. Touching the spinner displays a dropdown menu with all other available values, from which the
user can select a new one.
IMAGES
A single complete image buffer to use with a media source such as a MediaCodec or a CameraDevice.
This class allows for efficient direct application access to the pixel data of the Image through one or more
ByteBuffers. Each buffer is encapsulated in a Plane that describes the layout of the pixel data in that plane. Due
to this direct access, and unlike the Bitmap class, Images are not directly usable as UI resources.
MENU
In android, Options Menu is a primary collection of menu items for an activity and it is useful to implement
actions that have a global impact on the app, such as Settings, Search, etc.
In case, if we define items for the options menu in both activity or fragment, then those items will be combine
and display in UI.
DIALOG
A dialog is a small window that prompts the user to make a decision or enter additional information. A dialog
does not fill the screen and is normally used for modal events that require users to take an action before they can
proceed.
The Dialog class is the base class for dialogs, but you should avoid instantiating Dialog directly. Instead, use
one of the following subclasses:
AlertDialog : A dialog that can show a title, up to three buttons, a list of selectable items, or a custom
layout.
DatePickerDialog or TimePickerDialog : A dialog with a pre-defined UI that allows the user to select a
date or time.
DATABASE
UNDERSTANDING OF SQLite DATABASE
SQLite is a opensource SQL database that stores data to a text file on a device. Android comes in with built in
SQLite database implementation.
SQLite supports all the relational database features. In order to access this database, you don't need to establish
any kind of connections for it like JDBC,ODBC e.t.c
Database - Package
The main package is android.database.sqlite that contains the classes to manage your own databases
Database - Creation
In order to create a database you just need to call this method openOrCreateDatabase with your database name
and mode as a parameter. It returns an instance of SQLite database which you have to receive in your own
object.Its syntax is given below
This method only opens the existing database with the appropriate flag mode. The common flags
mode could be OPEN_READWRITE OPEN_READONLY
It is similar to the above method as it also opens the existing database but it does not define any
handler to handle the errors of databases
It not only opens but create the database if it not exists. This method is equivalent to openDatabase
method.
This method is similar to above method but it takes the File object as a path rather then a string. It is
equivalent to file.getPath()
This will insert some values into our table in our database. Another method that also does the same job but take
some additional parameter is given below
This method not only insert data , but also used to update or modify already existing data in database
using bind arguments
Database - Fetching
We can retrieve anything from database using an object of the Cursor class. We will call a method of this class
called rawQuery and it will return a resultset with the cursor pointing to the table. We can move the cursor
forward and retrieve the data.
There are other functions available in the Cursor class that allows us to effectively retrieve the data. That
includes
1 getColumnCount()
2 getColumnIndex(String columnName)
This method returns the index number of a column by specifying the name of the column
3 getColumnName(int columnIndex)
This method returns the name of the column by specifying the index of the column
4 getColumnNames()
This method returns the array of all the column names of the table.
6 getPosition()
This method returns the current position of the cursor in the table
7 isClosed()
This method returns true if the cursor is closed and return false otherwise
public DBHelper(){
super(context,DATABASE_NAME,null,1);
Example
Here is an example demonstrating the use of SQLite Database. It creates a basic contacts applications that
allows insertion, deletion and modification of contacts.
To experiment with this example, you need to run this on an actual device on which camera is supported.
Steps Description
2 Modify src/MainActivity.java file to get references of all the XML components and populate
the contacts on listView.
4 Create a new Activity as DisplayContact.java that will display the contact on the screen
10 Run the application and choose a running android device and install the application on it and verify
the results.
package com.example.sairamkrishna.myapplication;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import java.util.ArrayList;
import java.util.List;
DBHelper mydb;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
obj = (ListView)findViewById(R.id.listView1);
obj.setAdapter(arrayAdapter);
obj.setOnItemClickListener(new OnItemClickListener(){
@Override
dataBundle.putInt("id", id_To_Search);
intent.putExtras(dataBundle);
startActivity(intent);
});
return true;
@Override
super.onOptionsItemSelected(item);
switch(item.getItemId()) {
dataBundle.putInt("id", 0);
intent.putExtras(dataBundle);
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
{ if (keycode == KeyEvent.KEYCODE_BACK) {
moveTaskToBack(true);
package com.example.sairamkrishna.myapplication;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
int from_Where_I_Am_Coming = 0;
TextView name ;
TextView phone;
TextView email;
TextView street;
TextView place;
int id_To_Update = 0;
@Override
super.onCreate(savedInstanceState);
if(extras !=null) {
if(Value>0){
//means this is the view part not the add contact part.
Cursor rs = mydb.getData(Value);
id_To_Update = Value;
rs.moveToFirst();
if (!rs.isClosed()) {
rs.close();
Button b = (Button)findViewById(R.id.button1);
b.setVisibility(View.INVISIBLE);
name.setText((CharSequence)nam);
name.setFocusable(false);
phone.setText((CharSequence)phon);
phone.setFocusable(false);
phone.setClickable(false);
email.setText((CharSequence)emai);
email.setFocusable(false);
email.setClickable(false);
street.setText((CharSequence)stree);
street.setFocusable(false);
street.setClickable(false);
place.setText((CharSequence)plac);
place.setFocusable(false);
place.setClickable(false);
@Override
if(extras !=null) {
if(Value>0){
getMenuInflater().inflate(R.menu.display_contact, menu);
} else{ getMenuInflater().inflate(R.menu.menu_main
menu);
return true;
super.onOptionsItemSelected(item);
switch(item.getItemId()) {
case R.id.Edit_Contact:
Button b = (Button)findViewById(R.id.button1);
b.setVisibility(View.VISIBLE);
name.setEnabled(true);
name.setFocusableInTouchMode(true);
name.setClickable(true);
phone.setEnabled(true);
phone.setFocusableInTouchMode(true);
phone.setClickable(true);
email.setEnabled(true);
email.setFocusableInTouchMode(true);
email.setClickable(true);
street.setEnabled(true);
street.setFocusableInTouchMode(true);
street.setClickable(true);
place.setEnabled(true);
place.setFocusableInTouchMode(true);
place.setClickable(true);
return true;
case R.id.Delete_Contact:
builder.setMessage(R.string.deleteContact)
mydb.deleteContact(id_To_Update);
Toast.LENGTH_SHORT).show();
startActivity(intent);
})
});
AlertDialog d = builder.create();
d.show();
return true;
default:
return super.onOptionsItemSelected(item);
if(extras !=null) {
if(Value>0){
phone.getText().toString(), email.getText().toString(),
street.getText().toString(), place.getText().toString())){
Toast.makeText(getApplicationContext(), "Updated",
Intent(getApplicationContext(),MainActivity.class); startActivity(intent);
} else{
} else{
if(mydb.insertContact(name.getText().toString(), phone.getText().toString(),
email.getText().toString(), street.getText().toString(),
place.getText().toString())){
Toast.makeText(getApplicationContext(), "done",
Toast.LENGTH_SHORT).show();
done",
Toast.LENGTH_SHORT).show();
startActivity(intent);
package com.example.sairamkrishna.myapplication;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import android.content.ContentValues;
import android.content.Context;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase;
@Override
stub db.execSQL(
"(id integer primary key, name text,phone text,email text, street text,place text)"
);
@Override
public boolean insertContact (String name, String phone, String email, String street,String place)
{ SQLiteDatabase db = this.getWritableDatabase();
contentValues.put("name", name);
contentValues.put("phone", phone);
contentValues.put("email", email);
contentValues.put("street", street);
contentValues.put("place", place);
return true;
SQLiteDatabase db = this.getReadableDatabase();
return res;
SQLiteDatabase db = this.getReadableDatabase();
return numRows;
public boolean updateContact (Integer id, String name, String phone, String email, String street,String place)
{ SQLiteDatabase db = this.getWritableDatabase();
contentValues.put("name", name);
contentValues.put("phone", phone);
contentValues.put("email", email);
contentValues.put("place", place);
return true;
SQLiteDatabase db = this.getWritableDatabase();
return db.delete("contacts",
"id = ? ",
SQLiteDatabase db = this.getReadableDatabase();
res.moveToFirst();
while(res.isAfterLast() == false){
array_list.add(res.getString(res.getColumnIndex(CONTACTS_COLUMN_NAME)));
res.moveToNext();
return array_list;
<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:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="30dp"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tutorials Point"
android:id="@+id/textView2"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:textSize="35dp"
android:textColor="#ff16ff01" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:layout_below="@+id/textView2"
android:layout_centerHorizontal="true"
android:src="@drawable/logo"/>
<ScrollView
android:layout_height="wrap_content"
android:id="@+id/scrollView"
android:layout_below="@+id/imageView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true">
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >
</ListView>
</ScrollView>
</RelativeLayout>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".DisplayContact" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="370dp"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<EditText
android:id="@+id/editTextName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="5dp"
android:layout_marginLeft="82dp"
android:ems="10"
android:inputType="text" >
</EditText>
<EditText
android:id="@+id/editTextEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editTextStreet"
android:layout_below="@+id/editTextStreet"
android:layout_marginTop="22dp"
android:ems="10"
android:inputType="textEmailAddress" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/editTextName"
android:layout_alignParentLeft="true"
android:text="@string/name"
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editTextCity"
android:layout_alignParentBottom="true"
android:layout_marginBottom="28dp"
android:onClick="run"
android:text="@string/save" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/editTextEmail"
android:layout_alignLeft="@+id/textView1"
android:text="@string/email"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/editTextPhone"
android:layout_alignLeft="@+id/textView1"
android:text="@string/phone"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_above="@+id/editTextEmail"
android:layout_alignLeft="@+id/textView5"
android:text="@string/street"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/editTextCity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/editTextName"
android:layout_below="@+id/editTextEmail"
android:layout_marginTop="30dp"
android:ems="10"
android:inputType="text" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editTextCity"
android:layout_alignBottom="@+id/editTextCity"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/editTextEmail"
android:text="@string/country"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/editTextStreet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editTextName"
android:layout_below="@+id/editTextPhone"
android:inputType="text" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editTextPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editTextStreet"
android:layout_below="@+id/editTextName"
android:ems="10"
android:inputType="phone|text" />
</RelativeLayout>
</ScrollView>
<resources>
<string name="action_settings">Settings</string>
<string name="title_activity_display_contact">DisplayContact</string>
name="phone">Phone</string>
<string name="email">Email</string>
<string name="street">Street</string>
<string name="country">City/State/Zip</string>
<string name="no">No</string>
</resources>
<item android:id="@+id/item1"
android:icon="@drawable/add"
android:title="@string/Add_New" >
</item>
</menu>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
> <item
android:id="@+id/Edit_Contact"
android:orderInCategory="100"
android:title="@string/edit"/>
<item
android:id="@+id/Delete_Contact"
android:orderInCategory="100"
android:title="@string/delete"/>
</menu>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sairamkrishna.myapplication" >
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
</intent-filter>
</activity>
<activity android:name=".DisplayContact"/>
</application>
</manifest>
Let's try to run your application. I assume you have connected your actual Android Mobile device with your
computer. To run the app from Android studio , open one of your project's activity files and click Run icon
from the tool bar. Before starting your application,Android studio will display following window to select an
option where you want to run your Android application.
Select your mobile device as an option and then check your mobile device which will display following screen
Click on the add button of the menu screen to add a new contact. It will display the following screen −
It will display the following fields. Please enter the required information and click on save contact. It will
bring you back to main screen.
Now our contact has been added. In order to see where the database is created, open your android studio,
connect your mobile. Go tools/android/android device monitor. Now browse the file explorer tab. Now
browse this folder /data/data/<your.package.name>/databases<database-name>.
In Android, the SQLiteDatabase namespace defines the functionality to connect and manage a database. It
provides functionality to create, delete, manage and display database content.
Create a Database
SQLiteDatabase db;
Before you can use the above object, you must import the android.database.sqlite.SQLiteDatabasenamespace
in your application.
db=openOrCreateDatabase(String path, int mode, SQLiteDatabase.CursorFactory factory)
This method is used to create/open database. As the name suggests, it will open a database connection if it
is already there, otherwise it will create a new one.
Example,
db=openOrCreateDatabase("XYZ_Database",SQLiteDatabase.CREATE_IF_NECESSARY,null);
Arguments:
Int mode operating mode. Use 0 or "MODE_PRIVATE" for the default operation, or
"CREATE_IF_NECESSARY" if you like to give option that "if database is not
there, create it"
CursorFactory factory An optional factory class that is called to instantiate a cursor when query is called
This command is used to execute single SQL statement which doesn't return any data means other than
SELECT or any other.
Mobile Application Development Page | 49
db.execSQL("Create Table Temp (id Integer, name Text)");
In the above example, it takes "CREATE TABLE" statement of SQL. This will create a table of "Integer" &
"Text" fields.
Try and Catch block is require while performing this operation. An exception that indicates there was an
error with SQL parsing or execution.
This class is used to store a set of values. We can also say, it will map ColumnName and relavent ColumnValue.
values.put("id", eid.getText().toString());
values.put("name", ename.getText().toString());
String nullColumnHack If not set to null, the nullColumnHack parameter provides the name of nullable
column name to explicitly insert a NULL into in the case where yourvalues is
empty.
ContentValues values This map contains the initial column values for the row.
This method returns a long. The row ID of the newly inserted row, or -1 if an error occurred.
Example,
This interface provides random read-write access to the result set returned by a database query.
String []selectionArgs You may include ?s in where clause in the query, which will be replaced by
the values from selectionArgs. The values will be bound as Strings.
Example,
c.moveToFirst();
moveToNext Moves cursor pointer next to current position. while(!c.isAfterLast())
{
isAfterLast Returs false, if cursor pointer is not at last position of result //statement…
set. c.moveToNext();
}
It is very important to release our connections before closing our activity. It is advisable to release the
Database connectivity in "onStop" method. And Cursor connectivity after use it.
DatabaseDemoActivity.java
package com.DataBaseDemo;
import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnInsert=(Button)findViewById(R.id.button1);
try{
db=openOrCreateDatabase("StudentDB",SQLiteDatabase.CREATE_IF_NECESSARY,null);
db.execSQL("Create Table Temp(id integer,name text)");
}catch(SQLException e)
{
}
btnInsert.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
EditText eid=(EditText) findViewById(R.id.editText1);
EditText ename=(EditText)findViewById(R.id.editText2);
ContentValues values=new ContentValues();
values.put("id", eid.getText().toString());
values.put("name", ename.getText().toString());
if((db.insert("temp", null, values))!=-1)
{
Toast.makeText(DataBaseDemoActivity.this, "Record Successfully Inserted", 2000).show();
}
else
Mobile Application Development Page | 51
{
Toast.makeText(DataBaseDemoActivity.this, "Insert Error", 2000).show();
}
eid.setText("");
ename.setText("");
To see where your database is stored, (1)Start Your Emulator ( It is necessary to start Emulator to see
File Explorer content and (2) Open "File Explorer"
Data -> Data -> find your "package" -> databases -> "database"
With Google announcing that Kotlin is now its preferred language for Android app developers, the
language is proving to be a pragmatic, modern, and intuitive programming language. Kotlin is a
statically typed programming language for Java Virtual Machine (JVM) and JavaScript. Described as a
general-purpose language, Kotlin introduces functional features to support Java interoperability. The
Kotlin project was born out of the aspiration for heightened productivity with the goal to improve
the coding experience in a way that was both practical and effective. A central focus of Kotlin is to
enable mixed-language projects with improved syntax, as well as concise expressions and
abstractions. Accessibility on all platforms has always been a primary objective for Kotlin, but multi-
platform programming is only the premise to a much more innovative outlook.
Kotlin uses the compiler technology LLMV to compile Kotlin sources into stand-alone binaries for
multiple operating systems and CPU architectures like iOS, Linux, Windows, Mac, Webassembly etc
and mobile products like Pinterest, Twitter, Netflix, Uber, AirBnB, Trello, and Evernote are all
switching to Kotlin for Android applications.
While Java is a reputable programming language with vast open-source tools and libraries to help
developers, no language is without fault and maybe subject to complications that can make a it’s
developer’s job tedious. There are definite limitations within Java that impede Android API design. If
anything, Kotlin introduces solutions to common programming headaches and improve the Java
ecosystem as a whole. It is inherently lightweight, clean and far less verbose, especially in terms of
writing callbacks, data classes, and getters/setters.
public static double calculate (double a, String op, double b) throws Exception {
switch (op) {
case "add":
return a + b;
case "subtract":
return a - b;
case "multiply":
return a * b;
case "divide":
return a / b;
default:
}
}
Above is a simple calculator function written in Java. For comparison, here is the same calculator in
Kotlin:
when (op) {
Notice the Kotlin version of this calculator is written in half the lines of code it took to program the
function in Java hence writing large projects becomes easier when a developer is given more power
for every line of code. A key observation here is Kotlin does not overlook comprehension for the
sake of brevity. The syntax is concise, readable and still substantial. Other advantages of Kotlin over
java include Interoperability, Inbuilt Null Safety, No Raw Types, No Checked Exceptions, Reduced
Project Timelines and Fewer App Crashes