Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 67

Application Fundamentals

Mobile (Android)
Application Development
Creating
An Android Application

2
Step 01

3
Step 01 (Alternate Method)

4
Step 01 (Alternate Method)

5
Step 02

6
Step 02 (Enter Name)
 compiledSdkVersion is the platform version
against which you will compile your app. By
default, this is set to the latest version of Android
available in your SDK. (It should be Android 4.1 or
greater; if you don't have such a version available,
you must install one using the SDK Manager.) You
can still build your app to support older versions,
but setting this to the latest version allows you to
enable new features and optimize your app for a
great user experience on the latest devices.
 minSdkVersion is the Minimum SDK version you
specified during the New Project workflow. This is
the earliest version of the Android SDK that your
app supports.
 targetSdkVersion indicates the highest version of
Android with which you have tested your
application. As new versions of Android become
available, you should test your app on the new
version and update this value to match the latest
API level and thereby take advantage of new
platform features.

7
Step 03 (Skip - Press Next)

8
Step 04 (Skip - Press Next)

9
Step 05 (Skip - Press Next)

10
Step 06 (Skip - Press Finish)

11
New Application

12
New Application

13
Running
An Android Application

14
Run As “Android Application”

15
Run As “Android Application”

16
Android Virtual Device Manager

17
Android Virtual Device Manager

18
Android Virtual Device Manager

19
Create New AVD (Click New…)

20
Create New AVD (Fill & Click OK)

21
Android Virtual Device Manager

22
Run As “Android Application”

23
Wait For Emulator to Load...10+minutes

24
Emulator Running

25
Applications

26
Your First Application

27
Android Virtual Device Manager

28
Tips
 You can start a virtual device even before you
run an application.

 You can keep emulator running, so that you don’t have to


wait for it to load every time you want to run your app.

29
Using Hardware Devices
 Before we can run the application on a physical device, we
need to make a configuration change on the phone and
install some drivers for the phone on our development
machine.

30
Using Hardware Devices

Enable USB debugging on your device.


 On most devices running Android 3.2 or older, you can find
the option under Settings > Applications > Development.
 On Android 4.0 and newer, it's in Settings > Developer
options.
 On Android 4.2 and newer, Developer options is hidden by
default. To make it available, go to Settings > About phone
and tap Build number seven times. Return to the previous
screen to find Developer options.

31
Using Hardware Devices

Set up your system to detect your device.


 If you're developing on Windows, you need to install a USB
driver for adb (Android Debug Bridge).
 For an installation guide and links to OEM drivers, see the
OEM USB Drivers document:
 http://developer.android.com/tools/extras/oem-usb.html

32
Run As “Android Application”

33
Android Device Chooser

34
Running on Hardware Device

35
Files & Folders

36
Files & Folders

37
src
 If you expand this out you'll see the
package hierarchy.
 This is where all your source code
files will go.
 MainActivity.java: This is the auto-
generated Activity Class with the
name you entered into the project
creation wizard.

38
gen
 This folder will contain Java files that
get auto-generated by ADT.
 Do not modify these files under any
circumstances!
 BuildConfig.java contains configuration
for building the application
 R.java provides access to resources in
your application. Each resource has an
ID and are located here.
 It is an auto-generated file by aapt (Android
Asset Packaging Tool) that contains resource
IDs for all the resources of res/ directory.

39
Android 4.4.2
 This is the library of the Android
version you had chosen in the
project creation wizard.
 The application will be built using
this version of 'android.jar‘.

40
Android Private
Libraries
 The Android Support Library
package is a set of code libraries
that provide backward-compatible
versions of Android framework APIs
as well as features that are only
available through the library APIs.
 The JAR file present for this project
is android-support-v4.jar.
 More about the support libraries:
http://developer.android.com/tools/
extras/support-library.html
41
assets
 This folder is for asset files, such as
text and database files.

42
bin
 This folder contains files that are
built by ADT.
 It also contains APK (Application
Package File) file – used for
installing apps on android OS.

43
libs
 This is the location of all JAR files for
additional features and functionality
support in Android programming,
such as support libraries.
 You'll likely see android-support-
v4.jar in here.

44
res
 You should always externalize
resources such as images and strings
from your application code, so that
you can maintain them
independently. (allows you to
provide alternative resources that
support specific device
configurations such as different
languages or screen sizes)
 In order to provide compatibility
with different configurations, you
must organize resources in your
project's “res” directory, using
various sub-directories that group 45
res
 For any type of resource, you can
specify default and multiple alternative
resources for your application:
 Default resources are those that should
be used regardless of the device
configuration or when there are no
alternative resources that match the
current configuration.
 Alternative resources are those that
you've designed for use with a specific
configuration. To specify that a group of
resources are for a specific
configuration, append an appropriate
configuration qualifier to the directory
46
name.
res
 For example, while your default UI
layout is saved in the res/layout/
directory, you might specify a
different layout to be used when the
screen is in landscape orientation,
by saving it in the res/layout-land/
directory.
 Android automatically applies the
appropriate resources by matching
the device's current configuration to
your resource directory names.

47
Only Default Resource
 Two different devices, each using the default layout (the app provides no
alternative layouts).

48
Alternate Resource
 Two different devices, each using a different layout provided for different
screen sizes.

49
res
Some important resource types include:
 drawable: Bitmap files (.png, .9.png,
.jpg, .gif) or XML files that are
compiled into drawable resource.
 layout: XML files that define a user
interface layout.
 menu: XML files that define
application menus, such as an Options
Menu, Context Menu, or Sub Menu.
 values: XML files that contain simple
values, such as strings, string arrays,
quantity strings, integers, and colors.
50
Res (contd.)
Some other resource types are:
 Animation, Color State List, Style,
Bool, Color, Dimension, ID, Integer,
Integer Array, Typed Array

 More about Resource Types:


http://developer.android.com/guide
/topics/resources/available-resource
s.html

51
proguard-project.txt
 The ProGuard tool shrinks,
optimizes, and obfuscates your
code by removing unused code and
renaming classes, fields, and
methods with semantically obscure
names.
 The result is a smaller sized .apk file
that is more difficult to reverse
engineer.
 More about the ProGuard:
http://developer.android.com/tools/
help/proguard.html
52
project.properties
 This file contains all of the project
settings, such as the build target
you choose in the project creation
wizard.
 You should never edit this file
manually.
 If you wish to edit the project
properties, do so by right-clicking
the project in the 'Package Explorer'
panel, and selecting 'Properties'.

53
AndroidManifest.xml
 Every application must have an
AndroidManifest.xml file (with
precisely that name) in its root
directory.
 The manifest file presents essential
information about your app to the
Android system, information the
system must have before it can run
any of the app's code.
 More about the Manifest file:
http://developer.android.com/guide
/topics/manifest/manifest-intro.htm
l
54
AndroidManifest.xml
 Your app must declare all its
components in this file.
 Identify any user permissions the
app requires, such as Internet
access or read-access to the user's
contacts.
 Declare the minimum API Level
required by the app.
 Declare hardware and software
features used or required by the
app, such as a Camera, Bluetooth
services, or a Multi Touch screen.
55
Files & Folders
 You will most likely work with
following folders:
 src
 assests
 res
 AndroidManifest.xml

56
XML Introduction

57
What is XML?
 XML stands for EXtensible Markup Language

<?xml version="1.0"?>
<!-- This is a comment -->
<address>
<name>Lars</name>
<street>Test</street>
<telephone number="0123"/>
</address>

58
What is XML?
 XML stands for Extensible Markup Language and was
defined 1998 by the World Wide Web Consortium (W3C).
 An XML document consists of elements, each element has a
start tag, content and an end tag.
 An XML document must have exactly one root element (i.e.,
one tag which encloses the remaining tags).
 XML differentiates between capital and non-capital letters.

59
What is XML?
 An XML document always starts with a prolog which
describes the XML file. This prolog can be minimal, e.g. <?
xml version="1.0"?> or can contain other information, e.g.
the encoding, e.g. <?xml version="1.0" encoding="UTF-8”?>
 A tag which does not enclose any content is know as an
"empty tag". For example: <flag/>

60
What is XML?
Prolog
Start Tag
End Tag Comment

Root
Element <?xml version="1.0"?>
Empty Tag
<!-- This is a comment -->
<address>
<name>Lars</name>
<street>Test</street>
<telephone number="0123"/>
</address>

Content
Attribute

61
XML Advantages
 XML is plain text.
 XML represents data without defining how the data should
be displayed.
 XML can be transformed into other formats.
 XML can be easily processed via standard parsers.
 XML files are hierarchical.

62
Sample XML File
<?xml version="1.0" encoding="UTF-8"?>
<breakfastmenu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<calories>650</calories>
</food>
<food>
<name>French Toast</name>
<price>$4.50</price>
<calories>600</calories>
</food>
<food>
<name>Homestyle Breakfast</name>
<price>$6.95</price>
<calories>950</calories>
</food>
</breakfastmenu> 63
Wrap-up

64
Summary
 Creating an Android Application

 Running an Android Application

 Using Emulator

 Using Hardware Device

 Android Application Files & Folders

 XML Introduction

65
Exercise
 Exercise: Create & Run “Hello World” Android Application
(Optional: by using Resource File for strings), before next
class.

66
Q&A
67

You might also like