You are on page 1of 12

ANDROID LAUNCH: APP DEV

LEVEL:INTERMEDIATE

Android Development
{{Code Walk through}}
Victor Miclovich (Android developer and enthusiast)
@vicmiclovich

Objective
The objective of these notes is to accompany the session that will be held at the Google Uganda
office on Friday, May 6, 2011 at the Google Android developer challenge launch.
1. Proficiency in use and understanding of the Android software platform
2. Learning best practices
3. User Interface design
4. Planning an android application (includes prototyping, wireframes, etc.)

Materials
No extensive materials are needed in session; however, some of you may find the following useful
• Android documentation (http://developer.android.com)
• Books; many books have been written on this subject: Android wireless Development (Shane
Conder, et al. Second edition; ISBN 978-0-321-74301-5)

Procedures
1. Get to the Google offices on time
2. Fire up your laptops
3. We begin (fire up github, fire up eclipse and sharpen your hearing... not many people can
shout)

URLS: http://github.com/vicmiclovich

PAGE 1 OF 12

DURATION: 45 MINUTES
ANDROID LAUNCH: APP DEV

LEVEL:INTERMEDIATE

Setting up the Android development Environment


You may use a number of operating systems when working with Android. Currently, Google
provides support for UNIX based and windows operating systems. Please make sure you read
documentation that has been placed in http://developer.android.com
Supported Operating Systems
They include
I. Windows XP (check the google documentation for your windows version)
II. Mac OS X 10.5.8 or later (intel-based Mac work better magic)
III. Linux (I’ve used it on Ubuntu)

You need to have enough memory in your laptop in order to successfully develop android apps
without any pain (virtual memory can get used up when running the emulator and developer
tools).
Java Installation
The preferable java installation is JDK 6 (however, JD5 is still fine). You can get the latest java
downloads from Oracle’s website (http://oracle.com -> search for it). Linux users probably have
java installed; documentation on how to install in your various distros can be found in their
respective websites. Using a package manager such as apt-get, yum and others are advised as
dependencies of java do get installed too.
Installing the Eclipse IDE
As mentioned on facebook, Eclipse will be a requirement in order to get the best of these
sessions. Theoretic learning is actually boring; please use machines when attending developer
sessions. A couple of eclipse versions are out: Ganymede, Galileo and Helios (most of them are
named after “stars” lol!)
Note: These downloads tend to take forever, it is best that you do this in advance before you step
into the google office.
Installing the Android SDK
In order to build Android apps, you’ve got to use an Android SDK (Software Development Kit).
The Android SDK includes a set of predefined jars 1 , tools, and documentation. Newer versions
of the SDK are not downloaded from http://developer.android.com a special tool, was
refactored or designed in order to do just that; if you’ve successfully installed the eclipse plugin:
ADT 2, then you can access the AVD3 manager, a management interface that will help you choose
which API version of Android you’d want to develop in.

1 jars: java archives; classes compressed and packaged together


2 Android Developer Tool
3 Android virtual devices

PAGE 2 OF 12

DURATION: 45 MINUTES
ANDROID LAUNCH: APP DEV

LEVEL:INTERMEDIATE

Note: How to install plugins in Eclipse (Hellios)


There are 2 ways you can install plugins in Eclipse. Option 1) is to download individual plugin
packages (usually zipped/gzipped) and putting them in the /eclipse/plugins folder then accessing
the Help menu and clicking install new software:
Help >> Install New software
You get the following:

The next step is to click

Clicking “add”, takes you to


yet another dialog:

PAGE 3 OF 12

DURATION: 45 MINUTES
ANDROID LAUNCH: APP DEV

LEVEL:INTERMEDIATE

Because you downloaded a zipped plugin, you’ll have to choose “Archive” and point eclipse to
the location of your plugin:

Option 2) involves using an update site (url) that you feed into the eclipse “Add new software” or
“Update sites” feature/interface.
Note: this is well documented in http://developer.android.com.
Important Notes
On Linux, you’ll need to use a special file to set permissions for file access, root access and others
in order to have Android use the host operating system nicely.
I. Login as an administrator
II. create the file /etc/udev/rules.d/50-android.rules
III. For gutsy/hardy ubuntu installations the file should contain SUBSYSTEM== “usb”,
SYSFS{idVendor} == “obb4”, MODE= “0666” . For the Dapper linux distro
SUBSYSTEM== “usb_device”, SYSFS{idVendor} == “obb4”, MODE=
“0666”
IV. Enter chmod a+rx /etc/udev/rules.d/50-android.rules

PAGE 4 OF 12

DURATION: 45 MINUTES
ANDROID LAUNCH: APP DEV

LEVEL:INTERMEDIATE

Introducing Android
Creating Hello world
Note: This is not going to be part of the talk session (create this program after talk during break
out sessions; a url link to a github repository containing all source code will be provided).

This is pretty much the easiest app you can ever build on top of the Android platform. So, your
instructions follow.
1. Start a new android project in eclipse. Call it HelloGtug.
2. Set the build target (minimum API or version of Android) that you’d like to build for (in this
example I use 8).
3. Fill out the properties of your app (basic ones)
a. Application name: it can be any string (here it is Hello GTUGers)

PAGE 5 OF 12

DURATION: 45 MINUTES
ANDROID LAUNCH: APP DEV

LEVEL:INTERMEDIATE

b.Package name: this is usually through the use of java’s package naming convention for
packages (I use com.cwezi.gtugers)
c. Fill in the “Create Activity” section (optional, but advisable; here I call mine
SplashActivity)
d.The Min SDK Version is usually the same as your build target
4.Click “Finish” to create project.

PAGE 6 OF 12

DURATION: 45 MINUTES
ANDROID LAUNCH: APP DEV

LEVEL:INTERMEDIATE

The next step involves running the app. By default, the SDK already has a “hello world”. We’ll
just look at that in a bit. But first, what does eclipse create for us?
The following items are created:
• src/
• res/
• assets/
• gen/
• AndroidManifest.xml
• default.properties
• other meta data (proguard.cfg, .git/)

The src/ folder is where your java packages and class files are written, the res/ folder is where
you put stuff like images, string values, color values, styles and designs for app, layout attributes,
etc. The assets/ folder is a lot like the res/ folder, the only difference is that you can store
binary files and other data but that is read-only.
gen/ is a folder that stores compiled classes of your application... the .apk4 (android package) is
usually contains stuff generated and stored in gen/. In the gen/ folder, under the package, you
see a R.java file that’s been created for you; note that you must not change or update that file, the
plugin (ADT + eclipse) do that for you. Go ahead and open the file to see its contents.

We’ve covered the folders, but what of the rest? Well, the AndroidManifest.xml file is an
important file that allows the Android system to do the following
• manage installations and updates of your app
• display application details to users
• it helps launch app activities 5 (by setting or firing off permissions)
• manage application permissions (you wouldn’t want an app mis-using certain resources)
• handle advanced configurations

You can do amazing stuff with this file. The other remaining files aren’t as important (but they
should in a way always be present.)

4 The .apk file format is how Android packages applications


5 Activities are Android’s version of user interface components

PAGE 7 OF 12

DURATION: 45 MINUTES
ANDROID LAUNCH: APP DEV

LEVEL:INTERMEDIATE

Running the Hello GTUGers app


1.Create an AVD or virtual device/emulator that you’ll use to test
a. Click Window on the menu
b.Click Android SDK and AVD Manager

2.Run the application


a. Right click the application folder
within your eclipse workbench
(use the package explorer pane)
b.Click “Run As”
c. Click “Android application”

If you created the virtual device successfully and run the consequent steps then you should see an
emulator fire up with some Android goodness.

PAGE 8 OF 12

DURATION: 45 MINUTES
ANDROID LAUNCH: APP DEV

LEVEL:INTERMEDIATE

Note: Setting up the AVD


To make this a little bit fair, I’ll complete the steps of setting up the AVD.
In the previous page, when you reach the Android SDK and AVD manager, you’ll see options on
the right; choose “New” and then create device

PAGE 9 OF 12

DURATION: 45 MINUTES
ANDROID LAUNCH: APP DEV

LEVEL:INTERMEDIATE

Your app goes green

This is a really basic app that renders a view (Text).

PAGE 10 OF 12

DURATION: 45 MINUTES
ANDROID LAUNCH: APP DEV

LEVEL:INTERMEDIATE

Android’s Building Blocks


Android is a ubiquitous platform and it is no wonder that creating apps is a notch easier. Firstly,
a popular language is used (Java) and secondly a whole wide array of tools (open source and
others) have been created to translate basic stuff like HTML
or other scripting languages 6 to java and then to dalvik-
ready7 bytes.

Designing apps
Smartphone app design is always great when you start with
an idea, and from that idea you take a top-down approach to
development. In other words, start sketching out stuff on
napkins or pieces of paper. If that’s not enough, you can use
stencils, software8 and any thing that will help you concept
your app into something visible but non-
coded.
On your right, you see an example of
mspoti’s initial designs sketched on pieces of
paper. When apps are developed in a simple
ways, you get to see a bigger picture.

Apps in the Real world

CityProwler is an social networking application that allows users to know of places with the
most happening spots such as happy hour or Thirsty friday. Lists of events are listed in the app so
a user can know of the trending events in a neighborhood. To make things even more interesting,

6Check out “Phonegap” and “Titanium”, development frameworks that use scripting in HTML, javascript, and/or
python to build apps
7dalvik is a virtual machine designed to run on Android to fit on all machines (mobile and even toasters - android can
help make you breakfast); dalvik has less license restrictions than its counterpart Oracle’s jvm.
8 Such as Balsamiq mockups

PAGE 11 OF 12

DURATION: 45 MINUTES
ANDROID LAUNCH: APP DEV

LEVEL:INTERMEDIATE

this app awards users that go-out or “happen”9 the most. Using CityProwler, users can do at least
one of the following:
I. Post a status update
II. Create an Event
III. Browse event listings
IV. Participate in an event
V. Have a access to a timeline or feed

Using the above information, you can tell that this app should have about 5 different screens
available to the user. Luckily, CityProwler, probably has a backend service in some large or
mainstream site such as group or some other like mspoti. In order to maintain a constant stream
of updates, CityProwler has got to keep polling an API service where all this data is synced and
used.
What can such a typical android app use as building blocks?
In the presentation, you’ve probably seen or heard about Activities. An activity is a single screen
that a user sees on the device at one time; your typical app has multiple screens and hence
multiple activities.

An example application is being built up on github (for future reference, you may follow me on
github and watch the project) {cityprowler will have 2 versions, a premium ad-less version and
one with some ads}

TO-DO
Look through google’s documentation; it is quite exhaustive, make sure you download examples
and use that...

9hap.pen |ˈhapən|
verb [intrans.] to have fun in a new town or hot spot in town. Drink a lot, make out and do some more drinking. In
some situations, “happening” goes on to include dancing and other forms of merry-making.
PHRASES: happened: last night I happened.

PAGE 12 OF 12

DURATION: 45 MINUTES

You might also like