Android, A Quick Course
Author : Mathias SeguyCo-Author (Graphist): Yannick Bergès
Co-Author (Translator):Thomas Hatcher
Pages number : 201 pages
Publication Date: 15/06/2011
Published by http://android2ee.com
Original Title: Android, A Quick Course.
ISBN : 979-10-90388-04-8Copyright © 2011 by Mathias Séguy
EBook's goals
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 objets 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 internationalise it before finally delivering it to your client.This book therefore focuses on two main aspects :
- le savoir faire : How to Do
- le savoir concevoir : How to think about it
The “savoir faire” knowledge is illustrated in the examples of Android code that are :
- presented as “barebones”, without any functional consideration
- extremely precise and specific (ie 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 clarifeid
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 “savoir concevoir”, 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 to 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 manipulates fonts and characters, of the WebKit browser, pops up messages... This section of the book provides the information to make what most developers want and need : IHMs.The second part, that 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 it's counterpart the ContentProvider
- Use and define a Service.
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
And the last part explains the first step on Android application life's cycle: How to set the Android development environment.
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 screens” 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, compas, magnetic field, temperature...
- Keyboard management
- Font and character management
- Thread management
- Cycle of life events management
- Intents and Intents filter management
- Permissions management
- Ressource management
- Ressource files (internationalization and device trees), styles, themes,...
- Internal and external files
- Preferences
- SQLite data-base management
- Testing and the industrialization of the development
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.
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,...)
Table of Content
Android, A Quick Course............................................................................................................... 6
1 Introduction .................................................................................................................................... 9
1.1 Who is this book for?............................................................................................................. 10
1.2 Content ................................................................................................................................. 11
1.3 The structure of the book ...................................................................................................... 12
1.4 Conventions ........................................................................................................................... 13
1.5 Your workspace ..................................................................................................................... 13
The 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 ................................................................................................................... 21
3.5 Containers and evolved widgets ........................................................................................... 26
3.6 Methods for sizing 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 Pop-up messages: Toast and 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 Intent filters ........................................................................................................................... 58
5.4 Rotation ................................................................................................................................ 69
6 Resources ..................................................................................................................................... 70
6.1 Resource files ........................................................................................................................ 70
6.2 Managing preferences ........................................................................................................... 81
6.3 Local Databases ..................................................................................................................... 84
6.4 Files ....................................................................................................................................... 99
7 My application is a ContentProvider ........................................................................................... 103
7.1 Using a ContentProvider ..................................................................................................... 104
7.2 Definition of a ContentProvider .......................................................................................... 109
8 My application is a Service .......................................................................................................... 120
8.1 Using a service ..................................................................................................................... 120
8.2 Creating a service ................................................................................................................ 122
9 The manifest.xml file ................................................................................................................... 124
Communicating with the system ......................................................................................................... 126
10 Communicating outside of the activity ....................................................................................... 126
10.1 The internet ......................................................................................................................... 126
10.2 Permissions .......................................................................................................................... 135
10.3 Geo-localization ................................................................................................................... 138
10.4 MapView and MapActivity .................................................................................................. 142
10.5 Managing phone calls and SMS ........................................................................................... 146
10.6 Multimedia files and the camera ........................................................................................ 154
10.7 Managing Bluetooth, networks and WIFI............................................................................ 158
10.8 Interacting with the sensors ................................................................................................ 179
An Android project’s life cycle ............................................................................................................. 186
11 Installing a workspace ................................................................................................................. 186
11.1 Downloads ........................................................................................................................... 186
11.2 Setting up Eclipse ................................................................................................................ 187
Exhaustive Table Of Content ............................................................................................................... 192
Bibliography ........................................................................................................................................ 200
12 Books .......................................................................................................................................... 200
13 Online references: ....................................................................................................................... 200











