Android Application Development: - A Guide For The Intermediate Developer
Android Application Development: - A Guide For The Intermediate Developer
Benny Skogberg
Computer Science Department
School of Technology
Malmoö University
SE--205 06 Malmoö
Sweden
+46 (0)733 – 66 18 99
[email protected]
1. Abstract
The Degree Thesis in Computer Science focuses on development of Android applications to be used on a
handheld device running the Android Operating System (OS). It covers the basics such as setting up a
development environment, downloading appropriate tools and add--ons. The thesis serves as a guideline to
intermediate developers, seeking solutions to problems not discussed in available textbooks.
Android is a platform consisting of an operating system and a Software Development Kit (SDK) for handheld
devices. It originates from a small software company, acquired by Google and is now owned by Open handset
Alliance (OHA), where Google is a member. A description of Android is included and its advantages and
disadvantages are discussed. Resources and recommendations on Android development and Android
versioning are presented. Strategies on development are also suggested throughoutthis thesis.
The development for an Android device and its data traffic characteristics is of interest, which is also included
in this thesis. Connectivity and communication like connecting to Facebook and pulling data from an
internet--connected web server, is discussed.
2. Resumé
Examensuppsatsen i datavetenskap innehaå ller utveckling av mjukvara foö r Android som ska anvaö ndas av
handhaå llna enheter som anvaö nder operativsystemet Android. Uppsatsen omfattar grunderna saå som att
skapa en utvecklingsmiljoö samt att ladda ner laö mpliga verktyg och tillaö gg. Uppsatsen kan anvaö ndas som
riktlinjer foö r genomsnittsprogrammeraren som soö ker efter problemloö sningar som inte finns tillgaö nglig i
litteraturen.
Uppsatsen innehaå ller en beskrivning av Android samt en diskussion om dess foö rdelar och nackdelar foö rs.
Resurser och raå d foö r Androidutveckling ochAndroidversioner presenteras. Uppsatsen innehaå ller ocksaå
utvecklingsstrategier.
Utveckling foö r Android och dess egenskaper foö r datatrafik aö r intressanta, vilket ocksaå inkluderas i uppsatsen.
Uppkoppling gentemot Facebook och annan kommunikation saå som att haö mta data fraå n en webbserver
behandlas i uppsatsen.
4. List of Abbreviations
AVD Android Virtual Device. To be able to compile your solutions and run them as
application on an emulator you need to setup at least one AVD
DDMS Dalvik Debug Monitor Server. Connects your IDE to your AVD emulator. Every
Android application has its own Virtual Machine, not interfering with each
other
LBS Location--Based Service. Often used with a handheld devices’ Global Position
System receiver
One competitor to Apple iPhone OS is the Android OS. Android originates from a small software
company, acquired by Google and is now owned by Open Handset Alliance (OHA), where Google is a
member. OHA has over a hundredmember companies such as mobile operators, semiconductor
companies, handset manufacturers, software companies and commercialisation companies. Driven
through the Apache License, anyone can use the AndroidSoftware Development Kit (SDK) to
develop applications to run on the Android OS. Especially interesting for Android is its use of
common non--proprietary techniques such as the Javaprogramming language in combination with
Extensible Markup Language (XML). This makes it open, simple and easy to use for a substantial
part of the developer community.
The thesis reflects experiences of using XML, the Java Programming Language and Android SDK.
Questions answered are the following:
• What is Android and how does it work using Linux, XML and Java?
Since Android is a new software environment, there are few previous studies on this topic. Other
authors have made related work in books and articles, but a study likethis has, too my knowledge,
never been done before. Sharon P. Hall’s and Eric Anderson’s article “Operating Systems for Mobile
Computing” compares different mobile operating systems coming to the conclusion that Android is
uniquely positioned to facilitate all features of a Smartphone device [5]. Toshihiko Yamakami comes
to a similar conclusion stating “… foundation engineering and open source software significantly
impacts the software engineering in the mobile platform software”[10], based on his understanding
that no single vendor has the resources to develop all software (OS and applications). Jorge Aguö ero
et al. explain that the Java Android Library is similar to the Java Standard Edition in their article
“Towards on embedded agent model for Android Mobiles” [2].
Books [1] [4] [7] [9] on Android development also cover the setup of development environments on
different operating systems, but they fail to discussthe essential and fundamental aspect such as
role of the Secure Digital card (SD) size in the installation process. The author of this thesis has
reviewed such books and has noticed gaps and shortages in various areas. The literature [1] [4] [7]
[9] also has a tendency to discuss straight forward development and not the programmers’
everyday quest on finding errors. The thesis focuses on useful information for developers which is
hard to come by in books and articles. As the handheld Smartphone is primarily a communication
device, great attention will be paid ontelecommunication connectivity.
The thesis will not coverany financial aspects of Android. Although this thesis is not intended to
serve as a tutorial for developing Android applications, it will however present some examples of
code. This thesis has a focus on intermediate developers who wants to get an overview of Android
development and find useful information in setting up the development environmentand
connectivity with Android as well as finding answers to compiling errors they might run into.
• Android Programming Tutorials [7] by Murphy M. L. was selected to get the author quickly
up to speed on developing Android applications. It was the first search result using the
search string “Android tutorial” on the online bookstore Adlibris[11] December 18, 2009.
• Android Wireless Application Development [4] by Conder S. and Darcey L. was selected to
get the author a more deep understanding of Android fundamentals and features. It was the
• Pro Android Games [9] by Silva V. was selected to increase knowledge of graphic design,
since the gaming industry relies on graphics. It was the first search result using the search
string “Android games” on the online bookstore Adlibris [11] January 24, 2010.
• Unlocking Android [1] by Ableson F. et al. was selected to get the author a second book of
Android development fundamentals. It was the second search result using the search string
“Android development” on the online bookstore Amazon[12] January 24, 2010. The first
search result had already been purchased [4].
The selection of articles [2] [5] [10] used in this thesis is based on author’s evaluation from
searching in The ACM Digital Library[16] in December 2009. The criterion in the evaluation was
the three most relevant articles discussing development for Android handheld devices. From a
selection of 10--15 articles using search keywords; Android, Smartphone, OS and development in
various combination the author found these three articles most relevant.
• New Perspectives on XML [3] by Carey P. is literature taken from course Distributed
Information Systems at Malmoö University [24].
• Complete Java 2 Certification [6] by Heller P. and Roberts S. is literature taken from the
course Advanced Java Programming at Gothenburg University [22].
• Head First Java [8] by Sierra K. and Bates B. was selected by the highest user ratings by
participant of the course Advanced Java Programmingat Gothenburg University [22].
6.2 Method
This is an empirical qualitative study, based onreading above mentioned literature and testing their
examples. Tests are made by programming according to books and online resources, with the
explicit goal to find best practices and a more advanced understanding of Android.
One use case is presented in this thesis as a “Hello World!”--application, explaining what happens
behind the scenes. The other use case is a developed application which is presented at a conceptual
level.
Android is an open system, and is free to use by anyone. A handset manufacturer can use Android if
they follow the agreement stated in the Software Development Kit. Thereare no restrictions or
requirement for the handset manufacturer to share their extensions with anyone else, as there are
in other open source software, if they leave the Linux kernel as is. The Linux kernel is under a
different and more restricted license than Android.
Android is a software environment and not a hardware platform, which includes anOS, built on
Linux kernel--based OS hosting the Dalvik virtual machine. The Dalvik virtual machine runs Android
applications as instances of the virtual machine. Android contains a rich user interface, application
framework, Java class libraries and multimedia support [15]. Android also comes with built--in
applications containing features such as short message service functionality (messaging), phone
capabilities and an address book (contacts).
The downside of this freedom isthat users have to be very careful when uninstalling applications.
They could easily destroy parts of Android, making it unable to reboot.Another downside of
Android is its openness, which makes it more exposed to malware[25].
Figure 2: A timeline starting at the first open public release of Google API and Android SDK, the split of the two in
April 2009 until its latest release version 2.1 in January 2010.[30]
From a developer’s point of view, this is important. Considering the fact that thereare six different
versions of Android today and most certainly even more to come in the future, a developer needs to
master the different versions of Android. The challenge in building an applicationthat works well on
all different versions is one of the main issues with Android. One approach is to use the lowest
version possible for your application, making itaccessible to higher versions. The other approach is
The RunKeeper application, takes the latter approach, and was recently released to the Android
market in version 2.0. However, RunKeeper themselves state that the application will be supported
by earlier versions “in the near future”[27]. The design decision is inany case depending on a solid
and thought business decision, which impacts the whole development process. If not, the developer
is advised to address this to the stakeholders and project management.
To keep track of the currently used versions of Android, one option is to use the Android website
and turn your attention to the resources tab and navigate to Platform versions. There the people
interested can find by which Android version users have downloaded Android applications. It is a
rather blunt tool, showing you the last two weeks of download preceding a certain displayed date in
the Android Market. The pie diagram gives a quick overview bywhich versions Android users
download applications on a global scale. If your target market is not global, consider carrying out a
survey of your own, matching your target audience.
Even though the pie chart is a rough tool to use, the developer can get a quick overview of which
versions to target or to leave out. Developing a global application today the highest version to use
would be Android 1.5, since almost 4 of 10 devices downloading applications fromthe market are
using this version. Android version 1.1 is almost obsolete since only one out of a thousand use this
version. Android versions 2.0 and 2.0.1have not got that many downloads either, and can rely on
version 1.6.
The author suggests that a good strategy to develop an application published in the markettoday
would be to first release a version 1.5 followed by versions 1.6 and 2.1, leavingout version 1.1, 2.0
and 2.0.1. If the stakeholder only wants one Android application, version 1.5 would be a good
choice.
To develop an Android application, developers need to make sure that the development
environment has a Java version 5 or above. Today Java 6 is stableand there is really no reason not
to use it. Download and install a Java version appropriate forthe developing computer OS, since
Java is OS independent, developer could choose developing environment operating system freely
[1].
The AVD can be set up usingconsole application or the developers recently installed Eclipse ADT
plug--in. For convenience, developers are advised to set up all possible virtual devicesfrom the very
beginning. This approach makes development effort simpler later on, switching from one version of
virtual machine to another, especially in test purposes. The ADV is an emulator which actually
contains the specific Smartphone OS [1]. This is convenient if the developer does not have a device
of their own. Nonetheless the developer should be careful to release an applicationthat has not
been tested on an actual handset. The more different handsets and versions the developer tests
their application on, verifying functionality and purpose of application, the better. Releasing a fully
functional, well--tested and stable application to the Android market will increase user ratings
getting the developed application a better market placing.The default view of the Android market
application suggestions are presented in descending order by popularity, based on the number of
downloads and user ratings.
Android uses XML and Java in close conjunction, which might feel confusing at first.The files and
folder structure is very similar to any other Java application, with a few differences.
FirstApp.java is located in the java source folder src/apt/tutorial meaning that the package name is
apt.tutorial. When building applications that would be released to the Android market, the naming
convention is com.android.<company name>. The java source file (or files) contains all the
functionality of the application [1].
The resource folder, res, contains three different folders; drawable, for images and pictures; layout,
for the positioning and size of different elements such as buttons, text fields and the screen view,
and values for element names and colour.
The AndroidManifest.xml (Figure 5) is a simple XML file with an XML schema namespace called
android. It defines the java package, which icon to represent the application (in this casea file
The main.xml file (Figure 6), also specifying android namespace defines a linear layout, the
orientation (line 3) the layout width (line 4) and layout height (line 5). Orientation can be vertical,
horizontal or dependent on which way the Android device itself is oriented horizontal or vertical.
The TextView, lines 7--11, is an element, which is used to fill with text, in this case pointing to the
attribute hello in the element string.
Android uses XPath [3] tolocate the attribute value hello (line 3) of element string in the file
strings.xml (Figure 7). The value of this element is Hello World! On line 4, the attribute value
app_name is specified as First App referenced by AndroidManifest.xml.
The java--file FirstApp.java (Figure 8) is specified as an ordinary java--file beginning with the
package apt.tutorial (line 1). On line 3 and 4 this application imports the Activity class, and the
Bundle class. The class FirstApp (lines 6--14) inherits the Activity class. Line 8 and 9
onCreate-- method overrides the Activity class onCreate--method, taking the Bundle type
variable savedInstanceState as argument.
The saved instance state is a reference [6] to a place in memorywhere the application ran
previously. To this application it has no real value, but in lager applications itis crucial in terms of
multitasking. Android devices have limited resources, and are unable to run unlimited number of
applications at the same time. To mimic true multitasking, the application saves the instance state
to memory, when sent to background. The OS needs not to kill the application instantly, but if the
user continues to open other applications to a point close tothe resources limits, the OS terminates
the application. If the user returns to a killed application, its instance is still saved in memory; thus,
the OS starts the application again and grabs the saved instance state giving the impression the
application were never killed [13].
Continuing on line 11 the Activity class’s onCreate--method is called with the savedInstanceState
as argument. Last on line 12, the contentview is set with argument R.layout.main. R stands for the
resource folder res; layout is the subfolder and main the XML--file (Figure 6).
When the developer runs the application, the emulator most appropriate for the minSdkVersion
starts as an actual Android device. It takes the same time as starting an actual Android device, so
the developer is advised to keep the emulator running when developing applications for Android,
Be advised that Eclipse will generate twoequal and unfortunate warnings, which from a
developer’s perspective is annoying and unimportant. The warnings say “Warning once: This
application, or a library it uses, is usingNSQuickDrawView that has been deprecated. Apps should
cease use of QuickDraw and move toQuartz”. The developer should not be alarmed by this
deprecated message; it is just a warning that your environment is using a technique which would
not be supported later on. However– running the application on a real Smartphone device does
not generate these errors.
Figure 9: Emulator view when the compiled application runs from the Hello World application [7].
To be able to use Facebook connect, a user needs to have a Facebook account. The Android
application needs to facilitate a Facebook Developer application, set up within Facebook. Setting up
the application on Facebook is done using the Facebook Developer guidelines [18]. The Facebook
application is a framework where the developer can embed content from another server. Once
installed, the Facebook application needs not to change since the actual application, framed by
Facebook, is hosted on another server. Connecting to Facebook Connect lets the user sign in with
their Facebook account, sending an authentication token to the host server (the developer
controlled server), and verifying the user to the account on the internet--connected server. Once
signed in, the synchronization process starts. Users not having a Facebook account or users
unwilling to use a Facebook account for signing in, should also be able to sign in tothe server using a
username and a password.
The information container features are extended with more smart functions. It should make use of
user controlled settings, like synchronization interval and notifications. The Android application
will extend using instant, letter by letter, search result view finding contacts immediately. An option
can be using a Location Based Service (LBS) to be able to use ‘friends last seen’ functionality using
Google Maps.
There are other strategies too,such as a “quick win”. A “quick win” is a function having a high value
to the stakeholder, and one which is easy to develop. In this case one could develop the user
interface first, implementing only a part of the application but having the look and feel of the
application at hand. This has apparently a high value to the stakeholder, is easy to implement, and
gives a feeling for the application’s end result [31]. However, this strategy gives false hopeto the
stakeholder and an unwanted pressure on the developer to finish the application. To use this
strategy, the author suggests only showing the features and functions that are fully developed from
the user interface to the server and from the server to the user interface.
7. Result
7.1 Facebook Connect
Complementing the username/password login task the application needs to make use of the
Facebook connect feature. Today it’s seen on sites withinthe location--based social media sphere,
such as Foursquare [20] and Gowalla [23]. The general idea with Facebook connect on a handheld
device is to have your sign--in process just a click away, to improve usability. It can be a daunting
task typing long usernames and obscure passwords, especially on a small--screen Smartphone
with a touch control keyboard.
At this development stage you have your Facebook Application in place as a frame to your own host
web page. Three different Facebook users also tested this setup, to verify the application worked as
planned.
The third step is to access the Facebook Application using the Android Smartphone, to complete the
Facebook connect function. Facebook Connect for Android is hosted by Google Code[21] and is a port
of the Facebook Connect for iPhone. A port is a way of changinga software to make it usable for other
software environments. In this case it only uses the variables API key and API secret to connect you
to the correct Facebookapplication. The variable GetSessionCookie is also defined by Facebook
Connect for Android, but not used in thisapplication. If you were to use the actual Facebook
Application to more people than just sign in users, the variable GetSessionCookie is required to keep
the Smartphone connected to the Facebook Application.
When compiling the Android project, theemulator starts and theapplication is installed on the
emulator. Unlocking the emulator, the application starts, looking like an actual Android handheld
device. On start up a Facebook Connect button is visible and when activated you get the usual sign--
in form asking for username and password, since this emulator has not been connected to Facebook
before. Signing in with user credentials, the user is now actually connected to the Facebook
application and has the option to post a message on the user’s Facebook Wall using the developed
Android application.
A conceptual view of the Facebook Connect for Android is ni three layers. At the top layer, the user
handles her Smartphone which connects to the Facebook, the middle layer. The Facebook
Application uses your user credentials and connects to the host, the bottom layer.The application
images are not present, since the Facebook Connect does not support the Android WebView library.
The developer, as always, needs to use the correct Android version, andthe correct AVD emulator
version. In January 10, 2010 Facebook Connect for Android was updated from version 1.5 to 1.6.
7.2 Networking
When the Facebook Connect is working properly, the next step is to connect to the server. In a
general way, this is the same as connecting to any other server using the Hyper Text Transfer
Protocol (HTTP). Having your user credentials through Facebook Connect the application just
needs to connect to the server.
Since we are accessing data that is supposed to be concealed to the public and only accessible to
authorized users, we need to secure our network connection using the Secure Socket Layer (SSL).
Using SSL minimizes the risk of any unauthorized use of the private data.
It is possible to build the application in a simple sequential way; however this technique makes the
application slow. When connecting to a resource on theInternet, the probability of failure increases.
First, you have the Android device connected to a 3G--network, which might not have the best
signal strength at all times. Secondly the Internet resources could be occupied with numerous
requests from other sources or all together unavailable. A recommended approach for the
developer is to make use of threads when connecting to sources on theInternet [4]. Threading in
programming is used to make an application do several different things simultaneously, such as
handling user interface requests and at the same time download data from the Internet.
From a conceptual view, an application can work with multiple threads at the same time, keeping
the User Interface idle and functional to the user. It is also recommended to give the user the
When running threads, it is a good idea to have an event listener attached to the Internet connected
thread, since we want the user to be able to cancel the operation. This technique is also used in the
opposite direction. We want to tell the user when we have pulled all the required data from the
server, thus we make use of callbacks [8].
The author has experienced a lot of Android applications, downloaded from the Android market,
used on an Android device which has beenforced to quit by the Android OS. The main reason for this
is not known (since source code of applications is concealed), but one technique to minimize this
kind of behaviour is to make use of exception handling where this is appropriate. Validating user
input is not appropriate for exception handling, but using exceptions connecting to a resource to the
Internet is. The developer should make reasonable judgment on exceptions, since it slows down the
application. The general advice is to use exceptions only where the application is likely to crash for
reasons that are out of control and cannot be hindered by simpler programming constructs.
Therefore, we implement exception handling using try--catch statements on connections to the
Internet.
The next step is to compare theobjects from the local list of objects to the downloaded list of
objects. Each object has a unique identity and a timestamp, which determines whichobject was
edited last. Comparing time--stamps of the same identity determines which object has precedence
over the other. If the object on the server is newer, the local object is replaced by the one from the
server.
Iterating through the list in the above--described fashion, keeps the data accurate and
synchronized with the data on the server. Since there is only one user who updates her data, there
is no need to check if another user made any change.
Since server storage is set up ina way that only allows downloading all objects, improvements can
be made. A suggestion is to allow the Androidapplication to compare each object’s identity and
timestamp before downloading the entire object. This would not only increase usability in terms of
a faster application, but also decreases network load.
The openness of Android makes it more exposed to various malicious codes, than controlled
proprietary mobile operating systems. If a substantial number of Android devices are infected by
virus or other malicious code, it could jeopardize the whole Open Handset Alliance’s effort to stay
open. There are reports of bank fraudfrom applications downloaded from the Android Market,
which is not as guarded as Apples AppStore. With the growing popularity of Android, criminals is
more likely to pay more attention to Android applications and Android Marked [29].
Due to the rapid pace of new releases of Android versions, developers need to pay attention to the
development of versions as well as the current downloads made. Existing applications need to be
updated to newer versions, as users might not feel comfortable with older features on newer
Android devices. As in other software environments, it is most likelythat Android will also mature
as a programming language, making it more interesting for the corporate world and not just the
consumer market. A sales person might want to have an application connecting to thecompany’s
Customer Relationship Management system (CRM) having access to all to marketing valuable data
within hands reach. A Supply Chain Manager might want to check a warehouse inventory levels or
the one time delivery report. Possibilities are endless with Smartphone’s.
From a developer’s perspective, the use of common programming techniques is recommended. The
use of Java in combination with XML makes programming for Androidfairly simple for the
intermediate developer. The advantage is the possibility to use skills and techniques learned from
other programming languages. The disadvantage with Android from the developer’s perspective is
the rapid pace of new versions, whichputs a strain on the developer to continuously follow the
evolution of Android. Android is still in its early stages, and when it matures no one can tell.
9. Conclusion
This thesis has shown what Android is and how it works with XML in combination with Java. It has
described how to setup a development environment and the emulator (AVD). It has showed what
Issues of versioning of Android and its rapid evolvement in terms of new SDK’s have been discussed
as well as how developers should address these issues. The thesis has also discussed the advantages
and disadvantages with Android software environment, and has shown several tips for the
intermediate developer.
The author’s understanding is that Android and its SDK is a feature of the future.In part due to the
fact that it will be fun for must phone users to be able to add, develop and equip their phones with
new features and personal preferences, it will open a new era in sharing open source software
components, such free utilities and games, for mobile devices. Furthermore, Androidhas recently
arrived, and the author is convinced that the development environment and tools will be improved
and enhanced in the future, making the development process effective.