Android, A Complete Course, From Basics To Enterprise Edition
Author: Mathias SeguyCo-author : Yannick Bergès
Co-author : Thomas Hatcher
Pages number : 279 pages
Publication date:15/05/2011
Published by http://android2ee.com
Original Title: Android, A Complete Course, From Basics to Enterprise Edition. Édition Française.
ISBN : 979-10-90388-03-1
Copyright © 2011 by Mathias Séguy
You can find a review of the ebook on Best Android Books by LearnComputer.com
EBook's goal
Google's new operating system for mobile devices and tablets is here! The software already has a solid reputation and is invading the world of mobile communications; it is open-source and offers programmers Java development tools. It makes mobile development accessible to all objects developers with only a small investment needed to improve their skills. The only question is: Are you ready for it?The goal of this book is simply to allow you to become an autonomous Android programmer in record timing. If you are already a Java programmer (either beginner or advanced), the goal is for you to reach this autonomy in less than 10 days. This goal was what originally fueled the creation of this book: the necessity to offer my company's collaborators an effective and fast way to improve their skills. After reading this book you will be able to conceive an application, implement it, test it and internationalize it before finally delivering it to your client.
You also be able to know and understand what are the considerations to have when you’re in charge of an Android Application as a professional. What is the test strategy to use? How can you sign your application? How can you deploy it? How can you manage the life cycle of the application? How to implement continuous integration?
This book therefore focuses on two main aspects:
- How to?
- How to conceive?
- presented as “barebones”, without any functional consideration
- extremely precise and specific (i.e. a project for a combo-box, one for a web kit etc) that are there only to explain a certain concept in relation to a particular example
- commented and clarified
A short paragraph describes and explains the key ideas required to understand the code and then the code finishes the demonstration by illustrating the concept. This “savoir faire” will allow you to access the different problems raised by a given concept. On certain specific subjects that are particularly complex and that would require a much more detailed treatment, for the sake of fluidity, we will simply give introductory aspects that will allow you to pursue the question in your own time.
Concerning the “How to conceive” aspect, this book explains the key points of how an Android application is structured. It presents the various elements that make up the main architecture of the system and explicits how to build an application based on these principles and how to exploit it in the most effective way. Each one of the concepts is explained by a particular Android project containing examples of code.
The reader is encouraged to start by quickly reading the whole book without dwelling too much on each concept so that they might rapidly get an overview of how Android programming works. Then, the reader may refer to specific chapters of interest that he wishes to put to use. Once the reader has assessed the main considerations of any Android application, he may then acquire the “savoir faire” based on precise examples and use the provided code to build his own projects. Once all the skills have been acquired, this book will remain as a valuable source of information from which he might extract both ready-made code examples and explanations of the keys concepts associated with their use.
Content
This is broken down into four distinct parts.
The first part is aimed at developers and allows them to quickly make create applications containing graphical elements. This part describes and explains how to use components and how to structure an application. It therefore contains a description of the usual objects, keyboard management, menu management, of how to manipulate fonts and characters, of the WebKit browser and pop up messages. This section of the book provides the information to make what most developers want and need: IHMs.
The second part, which is more specifically aimed at developers / designers / architects, explains how to:
- Manage the processing associated to the activities (and the creation of threads).
- Manage an activity's life cycle.
- Use Android's event system with Intents.
- Manage resources (image files, text, colors, themes)
- Define and exploit a data base
- Use and define a ContentReceiver and its counterpart the ContentProvider
- Use and define a Service.
This second section deals with questions linked to developing the context of a company. It focuses on how to structure an Android application and how to respect the constraints of such a project.
The third part concentrates on how to:
- Communicate with the internet.
- Use http protocol to pass objects between a server of servlets and your application.
- Use other services and hence asking permission to do so.
- Use geo-localization and geo-coding
- Manage SMS and make phone calls
- Use multimedia files
- Use and manage Bluetooth, networks and WIFI.
- Communicate with device's sensors
This last point mainly looks at how to communicate with the system. It principally addresses developers/designers/architects who need to exploit the platform's already existing services.
The last part of the book focuses on an Android application’s life cycle. The first chapter of this final section takes a look at the tests strategies that are to be set up. Indeed, one of the great difficulties of Android programming is linked to the great number and diversity of different devices and system versions that an application is expected to comply with. The second chapter explains how to build the application and how to deploy it. Building and deployment of the application are also to be performed in a particular way when dealing with Android and it is necessary follow certain key steps and understand the process. Then, a long chapter will explore the ins and outs of managing the application’s life cycle via Maven. This type of management aims at bringing structure, serenity and agility to your project. But, the articulating Maven with Android is not a simple affair and depends on certain subtleties that we will take care to explicit. This books aims to present you with the various problems that you will have to face concerning compilation, testing and deployment. For every problem that have encountered we have tried to formulate an associated solution so that you may meet you own deadlines and goals without losing either your time or your nerves. The final chapter of the book looks at how to set up continuous integration by using Hudson and how to automate testing on a batch of different Android emulators.
Who is this book for ?
This book is written for several types of reader and will provide them with information that will allow them to reach their goals. What these readers all have in common is their desire to create Android based programs either for professional or amateur uses, as developers or as architects.
First of all, the amateur developer will be pleased to be able to quickly get their applications up and running thanks to the examples and simple explanations. The first part of the book explains how to set up the GUI (Graphical User Interfaces) for Android. Most amateur developers will want to focus on acquire an in depth knowledge of this aspect to become an efficient graphic programmer. Using the provided code examples, they will then be able to graft onto their GUI specific components and effortlessly improve their applications. The various components are:
- the Internet
- Using the HTTP bus
- Using MapView
- Using GeoCoder
- Making telephone calls
- Sending and receiving SMS
- Reading Audio files
- Reading/recording Video, taking a Photo
- Using Bluetooth
- Managing Network connections (GPRS, 3G, WIFI)
- Communicating with sensors: accelerometer, compass, magnetic field, temperature...
The second type of reader that this book is aimed at is the objects developer working in a company who needs to quickly get to grips with all the different structural aspects of an Android application, build GUIs and services, exploit and implement data bases, create http communication buses, manage resources and their internationalization... He will be able to have a lucid and concise overview of the whole system and rapidly create each of the required components whilst respecting both Android's coding rules and its philosophy. This book provides solutions to the main preoccupations that arise in company aimed applications.
- Keyboard management
- Font and character management
- Thread management
- Cycle of life events management
- Intents and Intents filter management
- Permissions management
- Resource management
- Resource files (internationalization and device trees), styles, themes...
- Internal and external files
- Preferences
- SQLite data-base management
- Testing and the industrialization of the development
The next type of reader is the architect, the designer, the information system project leader or the person responsible for pre-sales. This particular reader will acquire a birds-eye view of the system and learn how to combine the components together. The book will help him obtain a high-level vision of the system that will allow him to define the architecture of new Android application, know the full extent of services that the platform offers and create an estimate of the work to be done.
Finally, the last type of reader is the person that is responsible for either a major part or all of an Android project. This means project directors, technical directors, architects, advanced developers… This book proposes a way to set up an effective development environment and suggests an organized approach. It is capital for those in charge of projects to be fully aware of hundred and one different obstacles that may pop up during the process. Taking a project all the way from original conception to test automation builds on a remote continuous integration server is a long road full of potential pot-holes and pitfalls. This book wishes to provide you with numerous keys and to guide you down this road so as to be able to accomplish and complete projects.
Nevertheless, regardless of whatever category of reader might apply best to your profile, it is preferable that you have a minimum amount of knowledge concerning:
- Objet programming, knowing Java is even better.
- Using Eclipse (installing, setting up a workspace...)
If you have no knowledge concerning these two subjects but you are still interested in programming with Android, this book is also for you! You will begin to improve your skills but it will require more work and effort. But just think of how much pleasure you will get from seeing your first application available on AndroidStore or simply installed on your own mobile phone.
Table Of Content
Android, A Complete Course, From Basics to Enterprise Edition............................................................ 61 Introduction ........................................................................................................................................................ 9
1.1 Who is this book for?................................................................................................................................... 10
1.2 Content .......................................................................................................................................................... 11
1.3 The structure of the book ........................................................................................................................... 13
1.4 Conventions ................................................................................................................................................. 13
1.5 Your workspace ........................................................................................................................................... 13
Graphical User Interface ................................................................................................................................. 14
2 Fundamentals ................................................................................................................................................. 14
2.1 An Android application ................................................................................................................................ 14
2.2 Project structure ........................................................................................................................................... 15
3 The GUI’s Activities ......................................................................................................................................... 16
3.1 Using XML layouts ....................................................................................................................................... 16
3.2 Containers ..................................................................................................................................................... 17
3.3 Elementary widgets ..................................................................................................................................... 17
3.4 Selection widgets ......................................................................................................................................... 22
3.5 Containers and evolved widgets ............................................................................................................... 26
3.6 Methods for seizing text : Physical or software keyboard ..................................................................... 36
3.7 Menus ............................................................................................................................................................ 38
3.8 Typefaces ...................................................................................................................................................... 44
3.9 Integrating the WebKit navigator to an activity : the WebView widget ................................................ 45
3.10 Arising messages : Toast et AlertDialog ............................................................................................. 46
4 Manifest.xml and the layouts file ................................................................................................................. 47
4.1 The layouts file ............................................................................................................................................ 47
The heart of the system ................................................................................................................................... 48
5 Managing activities .......................................................................................................................................... 48
5.1 Threads .......................................................................................................................................................... 48
5.2 Managing events relative to an activity’s life cycle .................................................................................. 54
5.3 Intention filters .............................................................................................................................................. 58
5.4 Rotation .......................................................................................................................................................... 70
6 Resources ........................................................................................................................................................ 70
6.1 Resource files ............................................................................................................................................... 71
6.2 Managing preferences ................................................................................................................................ 82
6.3 Local Databases .......................................................................................................................................... 85
6.4 Files .............................................................................................................................................................. 101
7 My application is a ContentProvider ........................................................................................................... 106
7.1 Using a ContentProvider .......................................................................................................................... 106
7.2 Definition of a ContentProvider ............................................................................................................... 112
8 My application is a Service .......................................................................................................................... 123
8.1 Using a service .......................................................................................................................................... 123
8.2 Creating a service ..................................................................................................................................... 125
9 The manifest.xml file ................................................................................................................................... 127
Communicating with the system .................................................................................................................. 129
10 Communicating outside of the activity ................................................................................................... 129
10.1 The internet .............................................................................................................................................. 129
10.2 Permissions ............................................................................................................................................ 139
10.3 Geo-localization ...................................................................................................................................... 141
10.4 MapView and MapActivity ...................................................................................................................... 145
10.5 Managing phone calls and SMS .......................................................................................................... 150
10.6 Multimedia files and the camera ......................................................................................................... 158
10.7 Managing Bluetooth, networks and wifi ............................................................................................. 162
10.8 Interacting with the sensors ................................................................................................................. 183
An Android project’s life cycle ........................................................................................................................ 191
11 Installing a workspace ............................................................................................................................. 191
11.1 Downloads ............................................................................................................................................. 191
11.2 Setting up Eclipse ................................................................................................................................. 192
12 Testing your application .......................................................................................................................... 194
12.1 Testing the devices targetted by the application ............................................................................. 195
12.2 Setting up a test project ........................................................................................................................ 196
12.3 Testing an activity .................................................................................................................................. 196
12.4 Testing a ContentProvider ................................................................................................................... 201
12.5 Testing a service ................................................................................................................................... 205
12.6 Monkey and MonkeyRunner ................................................................................................................ 206
12.7 Maven and Hudson automate tests .................................................................................................. 208
13 Adding Jars to your Application ............................................................................................................. 208
14 Building and deploying your Application............................................................................................... 208
14.1 Signing an application.......................................................................................................................... 208
14.2 Deploying an application ..................................................................................................................... 210
14.3 Retrieving the key for MapView ........................................................................................................... 211
15 Maven and continuous integration ........................................................................................................ 212
15.1 Maven ....................................................................................................................................................... 212
15.2 Bringing together Android and Maven : The Ultimate Android Pom.............................................. 240
15.3 Hudson or test automation .................................................................................................................. 254
Detailed Table of Contents ........................................................................................................................... 269
Index .................................................................................................................................................................. 281
Bibliograpy ....................................................................................................................................................... 282
16 Books .......................................................................................................................................................... 282
17 Online references: .................................................................................................................................... 282











