1. Learning Android 1st Edition Marko Gargenta
download
https://ebookbell.com/product/learning-android-1st-edition-marko-
gargenta-2118630
Explore and download more ebooks at ebookbell.com
2. Here are some recommended products that we believe you will be
interested in. You can click the link to download.
Learning Android Application Testing Paul Blundell Diego Torres Milano
https://ebookbell.com/product/learning-android-application-testing-
paul-blundell-diego-torres-milano-50949106
Learning Android Develop Mobile Apps Using Java And Eclipse 2nd
Edition 2nd Edition Marko Gargenta
https://ebookbell.com/product/learning-android-develop-mobile-apps-
using-java-and-eclipse-2nd-edition-2nd-edition-marko-gargenta-23144940
Learning Android Game Programming A Handson Guide To Building Your
First Android Game 1st Edition Richard A Rogers
https://ebookbell.com/product/learning-android-game-programming-a-
handson-guide-to-building-your-first-android-game-1st-edition-richard-
a-rogers-2618536
Learning Android Canvas Mir Nauman Tahir
https://ebookbell.com/product/learning-android-canvas-mir-nauman-
tahir-4682566
3. Learning Android Application Programming For The Kindle Fire A Handson
Guide To Building Your First Android Application Lauren Darcey
https://ebookbell.com/product/learning-android-application-
programming-for-the-kindle-fire-a-handson-guide-to-building-your-
first-android-application-lauren-darcey-5474226
Learning Android Intents Muhammad Usama Bin Aftab Wajahat Karim
https://ebookbell.com/product/learning-android-intents-muhammad-usama-
bin-aftab-wajahat-karim-5497446
Learning Android Application Development Raimon Rafols Montane
https://ebookbell.com/product/learning-android-application-
development-raimon-rafols-montane-6808550
Learning Android Forensics Analyze Android Devices With The Latest
Forensic Tools And Techniques 2nd Ed Oleg Skulkin Donnie Tindall Rohit
Tamma
https://ebookbell.com/product/learning-android-forensics-analyze-
android-devices-with-the-latest-forensic-tools-and-techniques-2nd-ed-
oleg-skulkin-donnie-tindall-rohit-tamma-10551346
Learning Android Game Development Nikhil Malankar
https://ebookbell.com/product/learning-android-game-development-
nikhil-malankar-48956452
12. Setting Up a PATH to Tools 16
Installing Eclipse 16
Eclipse Workspace 17
Setting Up Android Development Tools 17
Hello, World 18
Creating a New Project 18
Manifest File 20
Layout XML Code 21
Strings 21
The R File 22
Java Source Code 22
The Emulator 23
An Emulator Versus a Physical Phone 25
Summary 25
4. Main Building Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
What Are Main Building Blocks? 27
A Real-World Example 27
Activities 28
Activity Life Cycle 28
Intents 31
Services 31
Content Providers 32
Broadcast Receivers 34
Application Context 34
Summary 35
5. Yamba Project Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
The Yamba Application 37
Design Philosophy 39
Project Design 39
Part 1: Android User Interface 39
Building an Activity 40
Networking and Multithreading 41
Debugging Android Apps 41
Part 2: Preferences, Filesystem, Options Menu, and Intents 41
The Activity 41
Menu System and Intents 42
Filesystem 42
Part 3: Android Services 42
Services 42
Application Object 42
Part 4: Working with Databases 42
vi | Table of Contents
13. SQLite and Android’s Support for It 42
Refactoring the Code Again 43
Part 5: Lists and Adapters 43
Timeline Activity 43
More Refactoring? 43
Part 6: Broadcast Receivers 43
Boot and Network Receivers 44
Timeline Receiver 44
Permissions 44
Part 7: Content Providers 44
Status Data 44
Android Widgets 44
Part 8: System Services 45
Compass and Location 45
Intent Service, Alarms, and Notifications 45
Summary 45
6. Android User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Two Ways to Create a User Interface 47
Declarative User Interface 47
Programmatic User Interface 48
The Best of Both Worlds 48
Views and Layouts 48
LinearLayout 49
TableLayout 50
FrameLayout 50
RelativeLayout 50
AbsoluteLayout 50
Starting the Yamba Project 51
The StatusActivity Layout 52
Important Widget Properties 54
Strings Resource 55
The StatusActivity Java Class 56
Creating Your Application-Specific Object and Initialization Code 56
Compiling Code and Building Your Projects: Saving Files 59
Adding the jtwitter.jar Library 59
Updating the Manifest File for Internet Permission 61
Logging in Android 62
LogCat 62
Threading in Android 65
Single Thread 65
Multithreaded Execution 66
AsyncTask 67
Table of Contents | vii
14. Other UI Events 70
Adding Color and Graphics 74
Adding Images 74
Adding Color 76
Alternative Resources 79
Optimizing the User Interface 80
Hierarchy Viewer 81
Summary 82
7. Preferences, the Filesystem, the Options Menu, and Intents . . . . . . . . . . . . . . . . . . 83
Preferences 83
Prefs Resource 84
PrefsActivity 87
Update the Manifest File 88
The Options Menu 89
The Menu Resource 89
Android System Resources 90
Update StatusActivity to Load the Menu 91
Update StatusActivity to Handle Menu Events 92
Strings Resource 92
Shared Preferences 93
The Filesystem Explained 95
Exploring the Filesystem 95
Filesystem Partitions 96
System Partition 96
SDCard Partition 96
The User Data Partition 97
Filesystem Security 98
Summary 99
8. Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
The Yamba Application Object 102
The YambaApplication Class 102
Update the Manifest File 104
Simplifying StatusActivity 105
UpdaterService 105
Creating the UpdaterService Java Class 106
Update the Manifest File 107
Add Menu Items 108
Update the Options Menu Handling 109
Testing the Service 109
Looping in the Service 110
Testing the Service 113
viii | Table of Contents
15. Pulling Data from Twitter 113
Testing the Service 117
Summary 117
9. The Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
About SQLite 119
DbHelper 120
The Database Schema and Its Creation 120
Four Major Operations 121
Cursors 122
First Example 122
Update UpdaterService 124
Testing the Service 127
Database Constraints 129
Refactoring Status Data 130
Summary 135
10. Lists and Adapters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
TimelineActivity 137
Basic TimelineActivity Layout 138
Introducing ScrollView 138
Creating the TimelineActivity Class 139
About Adapters 142
Adding a ListView to TimelineActivity 142
Creating a Row Layout 143
Creating an Adapter in TimelineActivity.java 144
TimelineAdapter 146
ViewBinder: A Better Alternative to TimelineAdapter 149
Updating the Manifest File 150
Initial App Setup 152
Base Activity 153
Toggle Service 154
Summary 159
11. Broadcast Receivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
About Broadcast Receivers 161
BootReceiver 162
Registering the BootReceiver with the AndroidManifest File 162
Testing the Boot Receiver 163
The TimelineReceiver 163
Broadcasting Intents 165
The Network Receiver 167
Adding Custom Permissions to Send and Receive Broadcasts 169
Table of Contents | ix
16. Declaring Permissions in the Manifest File 170
Updating the Services to Enforce Permissions 171
Updating TimelineReceiver to Enforce Permissions 172
Summary 173
12. Content Providers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
Creating a Content Provider 175
Defining the URI 176
Inserting Data 177
Updating Data 178
Deleting Data 179
Querying Data 179
Getting the Data Type 180
Updating the Android Manifest File 181
Using Content Providers Through Widgets 181
Implementing the YambaWidget class 182
Creating the XML Layout 185
Creating the AppWidgetProviderInfo File 185
Updating the Manifest File 186
Testing the Widget 186
Summary 186
13. System Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
Compass Demo 189
Common Steps in Using System Services 190
Getting Updates from the Compass 190
Compass Main Activity 191
Custom Rose Widget 194
Location Service 195
Where Am I? Demo 196
Updating Yamba to Use the Location Service 200
Updating Our Preferences 200
Updating the Yamba Application 201
Updating the Status Activity 202
Intent Service 206
Alarms 208
Adding an Interval to Preferences 209
Updating BootReceiver 210
Sending Notifications 212
Summary 214
14. The Android Interface Definition Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Implementing the Remote Service 215
x | Table of Contents
17. Writing the AIDL 216
Implementing the Service 217
Implementing a Parcel 218
Registering with the Manifest File 220
Implementing the Remote Client 221
Binding to the Remote Service 221
Testing That It All Works 224
Summary 225
15. The Native Development Kit (NDK) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
What Is and Isn’t the NDK For? 227
Problems Solved by the NDK 227
The Toolchain 228
Packaging Your Libs 228
Documentation and Standardized Headers 228
An NDK Example: Fibonacci 229
FibLib 229
The JNI Header File 231
C Implementation 232
The Makefile 234
Building the Shared Library 234
The Fibonacci Activity 235
Testing That It All Works 236
Summary 237
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Table of Contents | xi
19. Preface
This book sprang from years of delivering the Marakana Android Bootcamp training
class to thousands of software developers at some of the largest mobile companies
located on four continents around the world. Teaching this class, over time I saw what
works and what doesn’t. This book is a distilled version of the Android Bootcamp
training course that I developed at Marakana and fine-tuned over numerous
engagements.
My background is in Java from back before it was even called that. From the beginning,
I was very interested in embedded development as a way to program various devices
that surround us in everyday life. Because Java primarily took off in web application
development, most of my experience in the previous decade has been in building large
enterprise systems. Then Android arrived, and once again I became very excited about
building software for nontraditional computers. My current interests lie in using An-
droid on devices that may not even resemble a typical phone.
This book teaches anyone who knows Java (or a similar language) how to develop a
reasonably complex Android application. I hope you find this book fairly comprehen-
sive and that you find the example-based learning reasonably motivating. The goal of
Learning Android is to get you to think in Android terms.
What’s Inside
Chapter 1, Android Overview
Is an introduction to Android and its history
Chapter 2, The Stack
Is an overview of the Android operating system and all its parts from a very high
level
Chapter 3, Quick Start
Helps you set up your environment for Android application development
Chapter 4, Main Building Blocks
Explains the Android components application developers use to put together an
app
xiii
20. Chapter 5, Yamba Project Overview
Explains the Yamba application that we’ll build together through this book and
use as an example to learn Android’s various features
Chapter 6, Android User Interface
Explains how to build the user interface for your application
Chapter 7, Preferences, the Filesystem, the Options Menu, and Intents
Covers some of the operating system features that make an application developer’s
life easier
Chapter 8, Services
Covers building an Android service to process background tasks
Chapter 9, The Database
Explains the Android framework’s support for the built-in SQLite database and
how to use it to persist the data in your own application
Chapter 10, Lists and Adapters
Covers an important feature of Android that allows large data sets to be linked
efficiently to relatively small screens
Chapter 11, Broadcast Receivers
Explains how to use the publish-subscribe mechanism in Android to respond to
various system and user-defined messages
Chapter 12, Content Providers
Shows how to design a content provider to share data between applications, in this
case using it to enable our app widget to display data on the home screen
Chapter 13, System Services
Introduces various system services that an app developer can tap into
Chapter 14, The Android Interface Definition Language
Covers building an inter-process communication mechanism to allow for remote
access to a service from another application
Chapter 15, The Native Development Kit (NDK)
Introduces how to write native C code as part of your Android application
Conventions Used in This Book
The following typographical conventions are used in this book:
Italic
Indicates new terms, URLs, email addresses, filenames, and file extensions.
Constant width
Used for program listings, as well as within paragraphs to refer to program elements
such as variable or function names, data types, and XML entities.
Constant width bold
Shows commands or other text that should be typed literally by the user.
xiv | Preface
21. Constant width italic
Shows text that should be replaced with user-supplied values or by values deter-
mined by context.
This icon signifies a tip, suggestion, or general note.
This icon indicates a warning or caution.
Using Code Examples
This book is here to help you get your job done. In general, you may use the code in
this book in your programs and documentation. You do not need to contact us for
permission unless you’re reproducing a significant portion of the code. For example,
writing a program that uses several chunks of code from this book does not require
permission. Selling or distributing a CD-ROM of examples from O’Reilly books does
require permission. Answering a question by citing this book and quoting example
code does not require permission. Incorporating a significant amount of example code
from this book into your product’s documentation does require permission.
We appreciate, but do not require, attribution. An attribution usually includes the title,
author, publisher, and ISBN. For example: “Learning Android by Marko Gargenta
(O’Reilly). Copyright 2011 Marko Gargenta, 978-1-449-39050-1.”
If you feel your use of code examples falls outside fair use or the permission given here,
feel free to contact us at permissions@oreilly.com.
Safari® Books Online
Safari Books Online is an on-demand digital library that lets you easily
search over 7,500 technology and creative reference books and videos to
find the answers you need quickly.
Withasubscription,youcanreadanypageandwatchanyvideofromourlibraryonline.
Read books on your cell phone and mobile devices. Access new titles before they are
available for print, get exclusive access to manuscripts in development, and post feed-
back for the authors. Copy and paste code samples, organize your favorites, download
chapters, bookmark key sections, create notes, print out pages, and benefit from tons
of other time-saving features.
Preface | xv
22. O’Reilly Media has uploaded this book to the Safari Books Online service. To have full
digital access to this book and others on similar topics from O’Reilly and other pub-
lishers, sign up for free at http://my.safaribooksonline.com.
How to Contact Us
Please address comments and questions concerning this book to the publisher:
O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707 829-0104 (fax)
We have a web page for this book, where we list errata, examples, and any additional
information. You can access this page at:
http://oreilly.com/catalog/9781449390501/
To comment or ask technical questions about this book, send email to:
bookquestions@oreilly.com
For more information about our books, courses, conferences, and news, see our website
at http://oreilly.com.
Find us on Facebook: http://facebook.com/oreilly
Follow us on Twitter: http://twitter.com/oreillymedia
Watch us on YouTube: http://www.youtube.com/oreillymedia
Acknowledgments
This book is truly a result of outstanding teamwork. First, I’d like to thank my editors
at O’Reilly, Andy Oram and Brian Jepson. Andy, your comments were spot-on and
constructive. Brian, thank you for persuading me to take on writing this book in the
first place.
I would like to thank all my technical editors: Dan Bornstein, Hervé Guihot, Frank
Maker III, and Bill Schrickel. Thank you for diligently reading my half-baked drafts and
providing valuable comments.
This book wouldn’t be what it is without field testing it on our numerous clients. You
were the true pioneers on the cutting edge of Android, and your projects are all very
inspiring. Thank you for your trust.
xvi | Preface
23. I’d like to thank my team at Marakana—Aleksandar (Saša) Gargenta, Ken Jones, and
Laurent Tonon—for bringing back firsthand feedback from teaching Android Boot-
camp courses using the draft of this book. Saša, special thanks to you for sending me
back to the drawing board more times than I’d like to admit. This book is probably
months past due because of your in-depth technical comments.
And finally, a huge thanks to my wife, Lisa, and daughter, Kylie. I know what a sacrifice
it was for you while I was crisscrossing the world working on this material. Thank you
for supporting me along the way.
Preface | xvii
25. CHAPTER 1
Android Overview
In this chapter, you will learn how Android came about. We’ll take a look at its history
to help us understand its future. As this mobile environment enters a make-or-break
year, we look at the key players in this ecosystem, what motivates them, and what
strengths and weaknesses they bring to the table.
By the end of this chapter, you will better understand the ecosystem from a business
point of view, which should help clarify the technology choices and how they relate to
long-term advantages for various platforms.
Android Overview
Android is a comprehensive open source platform designed for mobile devices. It is
championed by Google and owned by Open Handset Alliance. The goal of the alliance
is to “accelerate innovation in mobile and offer consumers a richer, less expensive, and
better mobile experience.” Android is the vehicle to do so.
As such, Android is revolutionizing the mobile space. For the first time, it is a truly
open platform that separates the hardware from the software that runs on it. This allows
for a much larger number of devices to run the same applications and creates a much
richer ecosystem for developers and consumers.
Let’s break down some of these buzz words and see what’s behind them.
Comprehensive
Android is a comprehensive platform, which means it is a complete software stack for
a mobile device.
For developers, Android provides all the tools and frameworks for developing mobile
apps quickly and easily. The Android SDK is all you need to start developing for An-
droid; you don’t even need a physical phone.
1
26. For users, Android just works right out of the box. Additionally, users can customize
their phone experience substantially.
For manufacturers, it is the complete solution for running their devices. Other than
some hardware-specific drivers, Android provides everything else to make their devices
work.
Open Source Platform
Android is an open source platform. The entire stack, from low-level Linux modules
all the way to native libraries, and from the application framework to complete appli-
cations, is totally open.
More so, Android is licensed under business-friendly licenses (Apache/MIT) so that
others can freely extend it and use it for variety of purposes. Even some third-party
open source libraries that were brought into the Android stack were rewritten under
new license terms.
So, as a developer, you have access to the entire platform source code. This allows you
to see how the guts of the Android operating system work. As manufacturer, you can
easily port Android OS to your specific hardware. You can also add your own propri-
etary secret sauce, and you do not have to push it back to the development community
if you don’t want to.
There’s no need to license Android. You can start using it and modifying it today, and
there are no strings attached. More so, Android has many hooks at various levels of the
platform, allowing anyone to extend it in unforeseen ways.
There are couple of minor low-level pieces of code that are proprietary
to each vendor, such as the software stack for the cellular, WiFi, and
Bluetooth radios. Android tries hard to abstract those components with
interfaces so that vendor-specific code can be managed easily.
Designed for Mobile Devices
Android is a purpose-built platform for mobile devices. When designing Android, the
team looked at which mobile device constraints likely were not going to change for the
foreseeable future. For one, mobile devices are battery powered, and battery perform-
ance likely is not going to get much better any time soon. Second, the small size of
mobile devices means that they will always be limited in terms of memory and speed.
These constraints were taken into consideration from the get-go and were addressed
throughout the platform. The result is an overall better user experience.
Android was designed to run on all sorts of physical devices. Android doesn’t make
any assumptions about a device’s screen size, resolution, chipset, and so on. Its core is
designed to be portable.
2 | Chapter 1: Android Overview
27. History
The history of Android is interesting and offers some perspective on what the future
might hold.
These are the key events of the past few years:
• In 2005, Google buys Android, Inc. The world thinks a “gPhone” is about to come
out.
• Everything goes quiet for a while.
• In 2007, the Open Handset Alliance is announced. Android is officially open
sourced.
• In 2008, the Android SDK 1.0 is released. The G1 phone, manufactured by HTC
and sold by the wireless carrier T-Mobile USA, follows shortly afterward.
• 2009 sees a proliferation of Android-based devices. New versions of the operating
system are released: Cupcake (1.5), Donut (1.6), and Eclair (2.0 and 2.1). More
than 20 devices run Android.
• In 2010, Android is second only to Blackberry as the best-selling smart phone
platform. Froyo (Android 2.2) is released and so are more than 60 devices that
run it.
In 2005, when Google purchased Android, Inc., the world thought Google was about
to enter the smart phone market, and there were widespread speculations about a de-
vice called the gPhone.
Google’s CEO, Eric Schmidt, made it clear right away that Android’s ambitions were
much larger than a single phone. Instead, they envisioned a platform that would enable
many phones and other devices.
Google’s Motivation
Google’s motivation for supporting the Android project seems to be having Android
everywhere and by doing that, creating a level playing field for mobile devices. Ulti-
mately, Google is a media company, and its business model is based on selling adver-
tising. If everyone is using Android, then Google can provide additional services on top
of it and compete fairly. This is unlike the business models of other software vendors
who depend on licensing fees.
Although Google does license some proprietary apps, such as Gmail and Maps, and
makes some money off the Android market, its primary motivation is still the adver-
tising revenue that those apps bring in.
History | 3
28. Open Handset Alliance
For this to be bigger than just Google, Android is owned by the Open Handset Alliance,
a nonprofit group formed by key mobile operators, manufacturers, carriers, and others.
The alliance is committed to openness and innovation for the mobile user experience.
In practice, the alliance is still very young and many members are still learning to work
with each other. Google happens to be putting the most muscle behind the Android
project at the moment.
The first version of the Android SDK was released without an actual
phone on the market. The point of this is that you don’t really need a
phone for Android development. There are some exceptions (hardware
sensors, telephony, etc.), but for the most part the Android SDK con-
tains everything you’ll need for developing on this platform.
Android Versions
Like any software, Android is improved over time, which is reflected in its version
numbers. However, the relationship between different version numbers can be con-
fusing. Table 1-1 helps explain that.
Table 1-1. Android versions through Android 2.3
Android version API level Nickname
Android 1.0 1
Android 1.1 2
Android 1.5 3 Cupcake
Android 1.6 4 Donut
Android 2.0 5 Eclair
Android 2.01 6 Eclair
Android 2.1 7 Eclair
Android 2.2 8 Froyo (frozen yogurt)
Android 2.3 9 Gingerbread
Android 2.3.3 10 Gingerbread
Android 3.0 11 Honeycomb
The Android version number itself partly tells the story of the software platform’s major
and minor releases. What is most important is the API level. Version numbers change
all the time, sometimes because the APIs have changed, and other times because of
minor bug fixes or performance improvements.
4 | Chapter 1: Android Overview
29. As application developers, you will want to make sure you know which API level your
application is targeting in order to run. That API level will determine which devices can
and cannot run your application.
Typically your objective is to have your application run on as many devices as possible.
So, with that in mind, try to shoot for an API level that is as low as possible. Keep in
mind the distribution of Android versions on real devices out there. Figure 1-1 shows
a snapshot of the Android Device Dashboard from mid-2010.
Figure 1-1. Historical Android version distribution through January 2011
You may notice that there are not a lot of users of Android 1.5 and 1.6. You may also
notice that not a lot of users have the latest and greatest Android 2.3, but the number
of 2.x users is growing. This is because everyone with 1.0 and 1.1 got upgraded over
the air (OTA) automatically to 1.5. On the other hand, users who still have devices
with Android 1.5 and 1.6 likely will never be able to upgrade to 2.x versions. Their
older devices do not have the relevant firmware, and most manufacturers are not plan-
ning on releasing firmware upgrades as they are busy working on new models.
With that in mind, you will probably choose 1.6 or 2.0 as your minimum development
target, unless you truly need the features of the latest version.
Summary
The Android operating system was designed from the ground up to be a comprehensive
open source platform for mobile devices. It is a game-changer in the industry and has
enjoyed great success.
In the next chapter, we’ll take a look at the entire Android operating system at a high
level to gain a technical understanding of how all the pieces fit together.
Summary | 5
31. CHAPTER 2
The Stack
This is the 9,000-foot overview of the Android platform. Although you’re concerned
primarily with writing Android applications, understanding the layout of the system
will help shape your understanding about what you can or cannot do easily with
Android.
By the end of this chapter, you’ll understand how the whole system works, at least from
the high level.
Stack Overview
The Android operating system is like a cake consisting of various layers. Each layer has
its own characteristics and purpose. The layers are not cleanly separated but often seep
into each other.
When you read through this chapter, keep in mind that I am concerned only with the
big picture of the entire system and will get into the nitty-gritty details later on. Fig-
ure 2-1 shows the parts of the Android stack.
Linux
Android is built on top of Linux. Linux is a great operating system and the poster child
of open source. There are many good reasons for choosing Linux as the base of the
Android stack. Some of the main ones are its portability, security, and features.
Portability
Linux is a portable platform that is relatively easy to compile on various hardware
architectures. What Linux brings to Android is a level of hardware abstractions. By
basing Android on Linux, we don’t have to worry too much about underlying hardware
features. Most low-level parts of Linux have been written in fairly portable C code,
which allows for third parties to port Android to a variety of devices.
7
32. Figure 2-1. Android stack
Security
Linux is a highly secure system, having been tried and tested through some very harsh
environments over the decades. Android heavily relies on Linux for security. All An-
droid applications run as separate Linux processes with permissions set by the Linux
system. As such, Android passes many security concerns to the underlying Linux
system.
Features
Linux comes with a lot of very useful features. Android leverages many of them, such
as support for memory management, power management, and networking.
8 | Chapter 2: The Stack
33. Native Libraries
The native libraries are C/C++ libraries, often taken from the open source community
in order to provide necessary services to the Android application layer. Among others,
they include:
Webkit
A fast web-rendering engine used by Safari, Chrome, and other browsers
SQLite
A full-featured SQL database
Apache Harmony
An open source implementation of Java
OpenGL
3D graphics libraries
OpenSSL
The secure locket layer
Although many of these libraries are used as-is, one notable exception is Bionic, which
is basically a rewritten version of the standard C library. Bionic is used for two reasons:
Technology
To make it purpose-built for tiny, battery-powered devices
License
To make it license-friendly for others who might want to adopt it and change it
GNU libc, the default C library for Linux, is licensed under a GPL li-
cense, which requires any changes that you release publicly to be pushed
back to the open source community. As such, it might not be the most
business-friendly open source license when a company wants to keep
their derivative work proprietary. Bionic, on the other hand, is licensed
under an Apache/MIT license, which doesn’t require derivative works
to be open sourced.
Dalvik
Dalvik is a purpose-built virtual machine designed specifically for Android, developed
by Dan Bornstein and his team at Google.
The Java virtual machine (VM) was designed to be a one-size-fits-all solution, and the
Dalvik team felt they could do a better job by focusing strictly on mobile devices. They
looked at which constraints specific to a mobile environment are least likely to change
in the near future. One of these is battery life, and the other is processing power. Dalvik
was built from the ground up to address those constraints.
Dalvik | 9
34. Another side effect of replacing the Java VM with the Dalvik VM is the licensing.
Whereas the Java language, Java tools, and Java libraries are free, the Java virtual ma-
chine is not. This was more of an issue back in 2005 when the work on Dalvik started.
Nowadays, there are open source alternatives to Sun’s Java VM, namely the
OpenJDK and Apache Harmony projects.
By developing a truly open source and license-friendly virtual machine, Android yet
again provides a full-featured platform that others are encouraged to adopt for a variety
of devices without having to worry about the license.
Android and Java
In Java, you write your Java source file, compile it into a Java byte code using the Java
compiler, and then run this byte code on the Java VM. In Android, things are different.
You still write the Java source file, and you still compile it to Java byte code using the
same Java compiler. But at that point, you recompile it once again using the Dalvik
compiler to Dalvik byte code. It is this Dalvik byte code that is then executed on the
Dalvik VM. Figure 2-2 illustrates this comparison between standard Java (on the left)
in Android using Dalvik (on the right).
Figure 2-2. Java versus Dalvik
10 | Chapter 2: The Stack
35. It might sound like you have to do a lot more work with Android when
it comes to Java. However, all these compilation steps are automated
by tools such as Eclipse or Ant, and you never notice the additional
steps.
You may wonder, why not compile straight from Java into the Dalvik byte code? There
are a couple of good reasons for the extra steps. Back in 2005, when work on Dalvik
started, the Java language was going through frequent changes, but the Java byte code
was more or less set in stone. So, the Android team chose to base Dalvik on Java byte
code instead of Java source code.
A side effect of this is that in theory you could write Android applications in any other
language that compiles down to Java byte code. For example, you could use Python or
Ruby. I say “in theory” because in practice the appropriate libraries that are part of the
SDK would need to be available. But it is likely that the open source community will
come up with a solution to that in the future.
Another thing to keep in mind is that Android Java is a nonstandard collection of Java
classes. Java typically ships in:
Java Standard Edition
Used for development on basic desktop-type applications
Java Enterprise Edition (aka J2EE or JavaEE)
Used for development of enterprise applications
Java Micro Edition (aka J2ME or JavaME)
Java for mobile applications
Android’s Java set of libraries is closest to Java Standard Edition. The major difference
is that Java user interface libraries (AWT and Swing) have been taken out and replaced
with Android-specific user interface libraries. Android also adds quite a few new fea-
tures to standard Java while supporting most of Java’s standard features. So, you have
most of your favorite Java libraries at your disposal, plus many new ones.
Application Framework
The application framework is a rich environment that provides numerous services to
help you, the app developer, get your job done. This is the best-documented and most
extensively covered part of the platform because it is this layer that empowers devel-
opers to get creative and bring fantastic applications to the market.
In the application framework layer, you will find numerous Java libraries specifically
built for Android. You will also find many services (or managers) that provide the eco-
system of capabilities your application can tap into, such as location, sensors, WiFi,
telephony, and so on.
Application Framework | 11
36. As you explore Android application development, most of your focus will be on this
part of the stack, and you will get to use many of the application framework
components.
Applications
And finally, there are the applications that you and other developers create. These
applications are what end users find valuable about Android. They can come prein-
stalled on the device or can be downloaded from one of the many Android markets.
The APK
An application is a single application package (APK) file. An APK file roughly has three
main components. An API consists of the following major components:
Dalvik executable
This is all your Java source code compiled down to a Dalvik executable. This is the
code that runs your application.
Resources
Resources are everything that is not code. Your application may contain a number
of images and audio/video clips, as well as numerous XML files describing layouts,
language packs, and so on. Collectively, these items are the resources.
Native libraries
Optionally, your application may include some native code, such as C/C++ li-
braries. These libraries could be packaged together with your APK file.
Application Signing
Android applications must be signed before they can be installed on a device. For de-
velopment purposes, we’ll be signing our example applications with a debug key—a
key that you already have on your development platform. However, when you distrib-
ute your application commercially, you’ll want to sign it with your own key. The
Android developer document titled “Signing Your Application” has the details.
Application Distribution
One way in which Android is quite different from other platforms is the distribution
of its apps. On most other platforms, such as iPhone, a single vendor holds a monopoly
over the distribution of applications. On Android, there are many different stores, or
markets. Each market has its own set of policies with respect to what is allowed, how
the revenue is split, and so on. As such, Android is much more of a free market space
in which vendors compete for business.
12 | Chapter 2: The Stack
37. In practice, the biggest market currently is Android Market, run by Google. It is unclear
whether Google means to just seed the market space while other stores develop or plans
to make it a profitable venture.
Applications can also be distributed via the Web. When you download an APK file
from a website through the browser, the application represented by the APK file is
installed automatically on your phone.
What about viruses, malware, spyware, and other bad things?
With its decentralized application distribution system, it is certainly possible for an
unsuspecting user to download a malicious app that consequently does bad things. For
example, there have been reports of phishing attacks via fake banking apps.
So, Android leaves it to the marketplace to sort it out. Eventually, there will be stores
that are more reputable and those that are less so, at least in theory. Google relies on
user reports for policing its Android Market, but other stores may choose to do more
proactive testing and raise the bar on what gets into the store in the first place.
Summary
In this chapter, you got a big-picture overview of what comprises the Android operating
system and how its various pieces fit together. You now understand what makes An-
droid so complete, open, and attractive to developers.
In the next chapter, we’ll look at how to set up your development environment so you
can get up to speed quickly. We’ll also look at a simple Hello World application and
dissect it to help you understand the various pieces of an Android application.
Summary | 13
39. CHAPTER 3
Quick Start
In this chapter, you will learn how to set up your environment for Android develop-
ment. I’ll go beyond just listing where you can download the software, and will cover
some of the best practices in getting set up. I’ll look at development operating system
choices as well as the Android tools available. You will see the good, the bad, and the
ugly of the various tool and platform choices that you’re about to make (or that some-
one else has already made for you).
By the end of this chapter, you will have your entire development environment set up.
You’ll be able to write a Hello World application, build it, and run it on the emulator
(or a physical device, if you want).
I’m going to use ~ to refer to your home directory. On Mac OS X, that’s
typically something like /Users/marko. On Linux, it would be /home/
marko, and on Windows Vista and 7, C:Usersmarko (in Windows XP,
it would be C:Documents and Settingsmarko). Also, I’m going to use
Unix-style forward slashes and not Windows backslashes to denote file
path separators.
So, if you’re on Windows, just change ~ to C:UsersYourUserName
and/to.Otherthanthat,everythingshouldbeprettymuchfordifferent
operating systems, regardless of whether you use OS X, Linux, or
Windows.
Installing the Android SDK
The Android Software Development Kit (SDK) is all you need to develop applications
for Android. The SDK comes with a set of tools as well as a platform to run it and see
it all work. You can download the Android SDK for your particular platform from the
Android SDK Download page.
15
40. Once you download it, unzip (or on Linux, untar) it into a folder that is easy to get to.
Further examples in the book will assume your SDK is in the folder ~/android-sdk. If
it’s in a different location, use that location instead of ~/android-sdk. For example:
Windows
C:appsandroid-sdk-windows
Linux
/home/YourUserName/android-sdk-linux_86
Mac OS X
/Users/YourUserName/android-sdk-mac_86
For Windows users, I strongly recommend choosing directories without
spaces in them. This is because we’ll be doing work on the command
line and spaces just complicate things. Because the Windows XP home
directory is in C:Documents and Settings, I would recommend putting
android-sdk in a top-level directory that you create, such as C:apps.
However, on Windows Vista or 7, you can simply extract android-sdk
into C:UsersYourUserName.
Setting Up a PATH to Tools
The Android SDK has a folder that contains all its major tools. Since we’re going to use
these tools from the command line, it is very helpful to add your ~/android-sdk/tools/
and your ~/android-skd/platform-tools/ directories to your system PATH variable. This
will make it easier to access your tools without having to navigate to their specific
location every single time.
Details for setting up the PATH variable depend on the platform; see step 2 of the docu-
ment “Installing Android SDK”.
Installing Eclipse
Eclipse is an open source collection of programming tools originally created by IBM
for Java. Nowadays, most developers in the Java community favor Eclipse as their
Integrated Development Environment (IDE) of choice. Eclipse lives at http://eclipse.org.
Eclipse has a lot of time-saving features, which I’ll be pointing out as we continue. Keep
in mind that, although powerful, Eclipse tends to be very resource-hungry, and so you
might want to restart it once a day if it starts running sluggishly.
Although you can do Android development with any favorite text editor or integrated
development environment (IDE), most developers seem to be using Eclipse, and thus
that’s what I use in this book.
16 | Chapter 3: Quick Start
41. If you choose not to use Eclipse, please refer to “Developing in Other
IDEs”.
Download Eclipse at http://www.eclipse.org/downloads/. I recommend Eclipse IDE for
Java Developers (not the twice-as-large Eclipse for Java EE Developers). You can install
it in any directory you’d like.
Eclipse Workspace
Eclipse organizes all your work by projects. Projects are placed in a workspace, which
is a location you choose. So, where you put your workspace is significant. I recommend
~/workspace as a simple place for your code. On Windows, however, I recommend
storing your workspace in a directory that doesn’t have spaces in it (they complicate
anything you might do at the command line). C:workspace is a good choice for Win-
dows users.
Setting Up Android Development Tools
You also need to set up Android Tools for Eclipse. The instructions are:
1. Start Eclipse, then select Help→Install New Software (see Figure 3-1).
2. In the Available Software dialog, click Add.
3. In the Add Site dialog that appears, enter a name for the remote site (for example,
“Android Plugin”) in the “Name” field.
4. In the “Location” field, enter this URL: https://dl-ssl.google.com/android/
eclipse/.
5. Click OK.
6. Back in the Available Software view, you should now see “Developer Tools” added
to the list. Select the checkbox next to Developer Tools, which will automatically
select the nested tools Android DDMS and Android Development Tools. Click
Next.
7. In the resulting Install Details dialog, the Android DDMS and Android Develop-
ment Tools features are listed. Click Next to read and accept the license agreement
and install any dependencies, then click Finish.
8. Restart Eclipse.
If you have trouble downloading the plug-in, you can try using “http”
in the URL instead of “https” (https is preferred for security reasons).
Installing the Android SDK | 17
42. Hello, World
To make sure everything is set up properly, we’re going to write a simple Hello World
program. As a matter of fact, there’s not much for us to write, but a lot to understand.
This is because Eclipse will create the project shell for us from some predefined
templates.
Creating a New Project
In Eclipse, choose File→New→Android Project. Sometimes (especially the first time you
run Eclipse) the Android tools may not be appear there right away. They should show
up in the future after you’ve used them for the first time. If Android Project is not an
option under File→New, choose Other and look for Android Project in there.
Figure 3-1. Install new software
18 | Chapter 3: Quick Start
43. In the new project dialog window, fill out the following:
1. “Project name” is an Eclipse construct. Eclipse organizes everything into projects.
A project name should be one word. I like to use theCamelCase naming convention
here. Go ahead and type HelloWorld.
2. Next, you need to choose the build target. The build target tells the build tools
which version of the Android platform you are building for. In here you should see
a list of available platforms and add-ons you have installed as part of your SDK.
Go ahead and pick one of the newer ones, such as Android 2.2 (but don’t choose
the targets named Google APIs—those are Google’s proprietary extensions to the
Android platform). For our purposes, we’ll stick to Android Open Source versions
of the Android platform.
3. You need to fill out your project properties next. The application name is the plain
English name of your application. Go ahead and enter something like Hello,
World!!!.
4. The package name is a Java construct. In Java, all source code is organized into
packages. Packages are important because, among other things, they specify the
visibility of objects between the various Java classes in your project. In Android,
packages are also important for application signing purposes. Your package name
should be the reverse of your domain name with optional subdomains. I might use
com.example.calculator if I were building a calculator app and my domain name
was example.com. I’m going to be using com.marakana for my package name here.
5. You can optionally specify an activity. I haven’t covered activities yet (you’ll learn
abouttheminChapter6),butthinkofthemascorrespondingtothevariousscreens
in your application. An activity is going to be represented by a Java class, and
therefore its name should adhere to Java class naming conventions: start with an
upper-case letter and use CamelCase to separate words. So, type HelloWorld for
your activity name.
6. The minimum SDK version is the minimum version of Android—as represented
by API level—that is required for the device to run this application. You want this
number to be as low as possible so that your app can run on as many devices as
possible. I’m going to put 8 here to represent Android 2.2, which I know I have
installed.
Finally, click on the Finish button, and Eclipse will create your project. Let’s look at
the various files that this process created in Figure 3-2.
Hello, World | 19
44. Figure 3-2. HelloWorld new project window
Manifest File
The manifest file glues everything together. It is this file that explains what the appli-
cation consists of, what all its main building blocks are, what permissions it requires,
and so on (see Example 3-1).
20 | Chapter 3: Quick Start
45. Example 3-1. AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.marakana" android:versionCode="1" android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".HelloWorld" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="8" />
</manifest>
Layout XML Code
The layout file specifies the layout of your screen. In this case, shown in Example 3-2,
we have only one screen, and it’s loaded by the HelloWorld.java code seen in Exam-
ple 3-5.
Example 3-2. res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/hello" />
</LinearLayout>
Strings
This is another XML file that contains all the text that your application uses. For ex-
ample, the names of buttons, labels, default text, and similar types of strings go into
this file. This is the best practice for separating the concerns of various files, even if they
are XML files. In other words, layout XML is responsible for the layout of widgets, but
strings XML is responsible for their textual content (see Example 3-3).
Example 3-3. res/values/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, HelloWorld!</string>
<string name="app_name">Hello, World!!!</string>
</resources>
Hello, World | 21
46. The R File
The R file is the glue between the world of Java and the world of resources (see Exam-
ple 3-4). It is an automatically generated file, and as such, you never modify it. It is
recreated every time you change anything in the res directory, for example, when you
add an image or XML file.
You don’t need to look at this file much. We will use the data in it quite a bit, but we’ll
use Eclipse to help us refer to values stored in this file.
Example 3-4. gen/com/marakana/R.java
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package com.marakana;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}
Java Source Code
The Java code is what drives everything. This is the code that ultimately gets converted
to a Dalvik executable and runs your application (see Example 3-5).
Example 3-5. HelloWorld.java
package com.marakana;
import android.app.Activity;
import android.os.Bundle;
public class HelloWorld extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
22 | Chapter 3: Quick Start
47. setContentView(R.layout.main);
}
}
The Emulator
Running your application on a physical device versus an emulated device is pretty much
the same thing. That is because the emulator is an actual code emulator, meaning it
runs the same code base as the actual device, all the way down to the machine layer.
A simulator and an emulator sound very similar, but are fundamentally
different. To emulate means to imitate the machine executing the binary
code.So,anemulatorissortoflikeavirtualmachine.Asimulatormerely
simulates the behavior of the code at a higher level. Android SDK ships
with a true emulator, based on QEMU.
To use the emulator, we’ll have to create an Android Virtual Device (AVD). The easiest
way to do that is to start the android tool via Eclipse.
To create a new AVD, start the tool called Android SDK and AVD Manager (see Fig-
ure 3-3). You can start this tool from Eclipse by clicking on the icon or via the
command line by starting the tool called android, which is located in your SDK/tools
directory.
Figure 3-3. Android SDK and AVD Manager
From within the Android SDK and AVD Manager window, choosing “New…” pops
up a Create New AVD dialog window (see Figure 3-4). In this dialog, you specify the
The Emulator | 23
48. parameters for your new AVD. The name can be any name you choose. The target
designates which version of Android you want installed on this particular AVD. The
list of possible targets is based on platforms and add-ons that you have installed into
your SDK. If you don’t have any targets, go back to the Android SDK and AVD Manager
window and choose the “Available packages” tab to install at least one platform, for
example, Android 2.3 - API level 9.
Each AVD can have an SD card. You can just specify a number here for your built-in
card, in megabytes. The skin is the look and feel of your device as well as its form factor.
The Hardware option lets you fine-tune what this AVD does and doesn’t support.
Figure 3-4. New AVD dialog
Once you are done with this dialog, you will have an AVD in your list. Go ahead and
start it, and an emulator will pop up (see Figure 3-5).
24 | Chapter 3: Quick Start
49. Figure 3-5. Emulator
An Emulator Versus a Physical Phone
For the most part, running your application on the emulator is identical to running it
on a physical phone. There are some notable exceptions, mostly things that are just
hard to virtualize, such as sensors. Other hardware-related features such as telephony
and location services, can be simulated in the emulator.
Summary
Setting up the Android development environment basically involves setting up Android
SDK and Eclipse. Once you have set up your development environment, a good way
to test that everything is working is to use Eclipse to create a simple Hello World project
and run it in the emulator. If that runs fine, you are almost certain that your system is
set up and ready for further development.
Summary | 25
51. CHAPTER 4
Main Building Blocks
In this chapter, you will learn about the big blocks in Android. We’ll give you a high-
level overview of what activities are, how intents work, why services are cool, how to
use broadcast receivers and content providers to make your app scale, and much more.
By the end of this chapter, you will understand the main Android components for
building applications. You should conceptually know when you’d use what compo-
nent. You will also see how these components relate to a real-world application.
What Are Main Building Blocks?
The main building blocks are components that you use as an application developer to
build Android apps. They are the conceptual items that you put together to create a
bigger whole. When you start thinking about your application, it is good to take a top-
down approach. You design your application in terms of screens, features, and the
interactions between them. You start with conceptual drawing, something that you can
represent in terms of “lines and circles.” This approach to application development
helps you see the big picture—how the components fit together and how it all makes
sense.
A Real-World Example
Let’s say that we want to build a Twitter app. We know that the user should be able
to post status updates. We also know the user should be able to see what her friends
are up to. Those are basic features. Beyond that, the user should also be able to set her
username and password in order to log into her Twitter account. So, now we know we
should have these three screens.
Next, we would like this app to work quickly regardless of the network connection or
lack thereof. To achieve that, the app has to pull the data from Twitter when it’s online
and cache the data locally. That will require a service that runs in the background as
well as a database.
27
52. We also know that we’d like this background service to be started when the device is
initially turned on, so by the time the user first uses the app, there’s already up-to-date
information on her friends.
So, these are some straightforward requirements. Android building blocks make it easy
to break them down into conceptual units so that you can work on them independently,
and then easily put them together into a complete package.
Activities
An activity is usually a single screen that the user sees on the device at one time. An
application typically has multiple activities, and the user flips back and forth among
them. As such, activities are the most visible part of your application.
I usually use a website as an analogy for activities. Just like a website consists of multiple
pages, so does an Android application consist of multiple activities. Just like a website
has a “home page,” an Android app has a “main” activity, usually the one that is shown
first when you launch the application. And just like a website has to provide some sort
of navigation among various pages, an Android app should do the same.
On the Web, you can jump from a page on one website to a page on another. Similarly,
in Android, you could be looking at an activity of one application, but shortly after you
could start another activity in a completely separate application. For example, if you
are in your Contacts app and you choose to text a friend, you’d be launching the activity
to compose a text message in the Messaging application.
Activity Life Cycle
Launching an activity can be quite expensive. It may involve creating a new Linux
process, allocating memory for all the UI objects, inflating all the objects from XML
layouts, and setting up the whole screen. Since we’re doing a lot of work to launch an
activity, it would be a waste to just toss it out once the user leaves that screen. To avoid
this waste, the activity life cycle is managed via Activity Manager.
Activity Manager is responsible for creating, destroying, and managing activities. For
example, when the user starts an application for the first time, the Activity Manager
will create its activity and put it onto the screen. Later, when the user switches screens,
the Activity Manager will move that previous activity to a holding place. This way, if
the user wants to go back to an older activity, it can be started more quickly. Older
activities that the user hasn’t used in a while will be destroyed in order to free more
space for the currently active one. This mechanism is designed to help improve the
speed of the user interface and thus improve the overall user experience.
Programming for Android is conceptually different than programming for some other
environments. In Android, you find yourself responding more to certain changes in the
state of your application rather than driving that change yourself. It is a managed,
28 | Chapter 4: Main Building Blocks
53. container-based environment similar to programming for Java applets or servlets. So,
when it comes to an activity life cycle, you don’t get to say what state the activity is in,
but you have plenty of opportunity to say what happens during the transitions from
state to state. Figure 4-1 shows the states that an activity can go through.
Figure 4-1. Activity life cycle
Starting state
When an activity doesn’t exist in memory, it is in a starting state. While it’s starting up,
the activity will go through a whole set of callback methods that you as a developer
have an opportunity to fill out. Eventually, the activity will be in a running state.
Keep in mind that this transition from starting state to running state is one of the
most expensive operations in terms of computing time, and this also directly affects
thebatterylifeofthedevice.Thisistheexactreasonwhywedon’tautomaticallydestroy
activities that are no longer shown. The user might want to come back to them, so we
keep them around for a while.
Running state
The activity in a running state is the one that is currently on the screen and interacting
with the user. We also say this activity is in focus, meaning that all user interactions—
such as typing, touching the screen, and clicking buttons—are handled by this one
activity. As such, there is only one running activity at any given time.
Activities | 29
54. The running activity is the one that has priority in terms of getting the memory and
resources it needs to run as quickly as possible. This is because Android wants to make
sure the running activity is zippy and responsive to the user.
Paused state
When an activity is not in focus (i.e., not interacting with the user) but still visible on
the screen, we say it’s in a paused state. This is not a typical scenario, because the
device’s screen is usually small, and an activity is either taking up the whole screen or
none at all. We often see this case with dialog boxes that come up in front of an activity,
causing it to become Paused. All activities go through a paused state en route to being
stopped.
Paused activities still have high priority in terms of getting memory and other resources.
This is because they are visible and cannot be removed from the screen without making
it look very strange to the user.
Stopped state
When an activity is not visible, but still in memory, we say it’s in astopped state. Stopped
activity could be brought back to the front to become a Running activity again. Or, it
could be destroyed and removed from memory.
The system keeps activities around in a stopped state because it is likely that the user
will still want to get back to those activities some time soon, and restarting a stopped
activity is far cheaper than starting an activity from scratch. That is because we already
have all the objects loaded in memory and simply have to bring it all up to the
foreground.
Stopped activities can be removed from memory at any point.
Destroyed state
A destroyed activity is no longer in memory. The Activity Manager decided that this
activity is no longer needed and has removed it. Before the activity is destroyed, it can
perform certain actions, such as save any unsaved information. However, there’s no
guarantee that your activity will be stopped prior to being destroyed. It is possible for
a paused activity to be destroyed as well. For that reason, it is better to do important
work, such as saving unsaved data, en route to a paused state rather than a destroyed
state.
The fact that an activity is in a running state doesn’t mean it’s doing
much. It could be just sitting there and waiting for user input. Similarly,
an activity in a stopped state is not necessarily doing nothing. The state
names mostly refer to how active the activity is with respect to user
input, in other words, whether an activity is visible, in focus, or not
visible at all.
30 | Chapter 4: Main Building Blocks
60. This ebook is for the use of anyone anywhere in the United States and
most other parts of the world at no cost and with almost no restrictions
whatsoever. You may copy it, give it away or re-use it under the terms
of the Project Gutenberg License included with this ebook or online at
www.gutenberg.org. If you are not located in the United States, you
will have to check the laws of the country where you are located before
using this eBook.
Title: Dickensian Inns & Taverns
Author: B. W. Matz
Release date: June 10, 2013 [eBook #42908]
Most recently updated: October 23, 2024
Language: English
Credits: E-text prepared by the Online Distributed Proofreading Team
(http://www.pgdp.net) from page images generously made
available by Internet Archive (http://archive.org)
*** START OF THE PROJECT GUTENBERG EBOOK DICKENSIAN INNS &
TAVERNS ***
61. The Project Gutenberg eBook, Dickensian Inns & Taverns, by B. W.
(Bertram Waldrom) Matz, Illustrated by T. Onwhyn, Charles G. Harper,
L. Walker, F. G. Kitton, and G. M. Brimelow
Note: Images of the original pages are available through Internet
Archive. See
https://archive.org/details/dickensianinnsta00matziala
DICKENSIAN INNS AND TAVERNS
BY THE SAME AUTHOR
THE INNS AND TAVERNS OF PICKWICK
With thirty-one illustrations.
Large Crown 8vo. Second Edition.
10/6 net.
62. “The Inns and Taverns of Pickwick” has proved one of the most
successful books of the season. The reviewers have been
unanimous in its praise, and in speaking of its value and qualities
have used such adjectives as famous, friendly, entertaining,
delightful, well-informed, irresistible, valuable, fascinating, jolly,
glowing, jovial, great, favourite, charming, congenial, and agreed
that it is the “final authority and worthy of its mighty subject.”
LONDON: CECIL PALMER
JOHN BROWDIE AND FANNY SQUEERS ARRIVE
AT THE SARACEN’S HEAD
Drawn by T. Onwhyn
63. DICKENSIAN
INNS & TAVERNS
BY
B. W. MATZ
EDITOR OF “THE DICKENSIAN”
AUTHOR OF
“THE INNS AND TAVERNS OF PICKWICK”
ETC., ETC.
WITH THIRTY-NINE ILLUSTRATIONS BY T. ONWHYN,
CHARLES G. HARPER, L. WALKER, F. G. KITTON, G. M. BRIMELOW
AND FROM PHOTOGRAPHS AND OLD ENGRAVINGS
LONDON
CECIL PALMER
OAKLEY HOUSE, BLOOMSBURY STREET, W.C. I
First
Edition
1922
Copyright
64. Printed in Great Britain by Burleigh Ltd. Bristol
TO
RIDGWELL CULLUM
65. CONTENTS
Chapter Page
Preface 13
I Dickens and Inns 15
II Oliver Twist 22
III Nicholas Nickleby: The Saracen’s Head 32
IV Nicholas Nickleby (continued) 49
V Barnaby Rudge: The Maypole 72
VI Barnaby Rudge (continued) and The Old Curiosity Shop 89
VII Martin Chuzzlewit 105
VIII Dombey and Son 132
IX David Copperfield 144
X Bleak House, Little Dorrit, Hard Times 169
XI A Tale of Two Cities and Great Expectations 178
XII Our Mutual Friend 191
XIII Edwin Drood, and The Lazy Tour of Two Idle Apprentices 217
XIV Sketches by Boz, and The Uncommercial Traveller 239
XV Christmas Stories and Minor Writings 258
66. LIST OF ILLUSTRATIONS
John Browdie and Fanny Squeers arrive at the Saracen’s
Head. Drawn by T. Onwhyn
Frontispiece
The Red Lion, Barnet. Photo by T. W. Tyrell Page 24
The Coach and Horses, Isleworth. Drawn by C. G. Harper " 26
The Eight Bells, Hatfield. Drawn by F. G. Kitton " 29
The Sign of the Saracen’s Head " 35
The Saracen’s Head, Snow Hill. From an old print " 41
The Peacock, Islington. From an old engraving " 50
The George Inn, Greta Bridge. Drawn by C. G. Harper " 57
The King’s Head, Barnard Castle. Photo by T. W. Tyrrell " 60
The Bottom Inn, near Petersfield. Drawn by C. G. Harper " 65
The King’s Head, Chigwell. Drawn by L. Walker " 75
The Chester Room, King’s Head. Drawn by L. Walker " 82
The Old Boot Inn, 1780. From an old engraving " 91
The Red Lion, Bevis Marks. Drawn by G. M. Brimelow " 99
The George, Amesbury. Drawn by C. G. Harper " 111
The George Inn, Salisbury. Photo by T. W. Tyrrell " 114
The Black Bull, Holborn. Drawn by L. Walker " 121
The Sign of the Black Bull. Drawn by L. Walker " 129
The Bedford Hotel, Brighton. From an old engraving " 134
The Royal Hotel, Leamington. From a lithograph " 134
The Plough Inn, Blunderstone. Photo by T. W. Tyrrell " 146
The Buck Inn, Yarmouth. Photo by T. W. Tyrrell " 146
The Duke’s Head, Yarmouth. Photo by T. W. Tyrrell " 146
The Little Inn, Canterbury. Drawn by F. G. Kitton " 157
67. Jack Straw’s Castle. Drawn by L. Walker " 163
The London Coffee House. From an old engraving " 172
The Old Cheshire Cheese. From a photo " 180
The Ship and Lobster, Gravesend. Drawn by C. G. Harper " 187
The Grapes Inn, Limehouse. Photo by T. W. Tyrrell " 194
Limehouse Reach. Drawn by L. Walker " 199
The Ship Hotel, Greenwich. Drawn by L. Walker " 207
The Red Lion, Hampton. Drawn by C. G. Harper " 213
Wood’s Hotel, Furnival’s Inn. Drawn by L. Walker " 223
The King’s Arms, Lancaster. Drawn by L. Walker " 231
The Eagle Tavern. From an old print " 242
The Crispin and Crispianus. Drawn by C. G. Harper " 255
The Mitre Inn, Chatham. From an engraving " 259
The Lord Warden Hotel, Dover. From an engraving " 268
The Pavilion Hotel, Folkestone. From an engraving " 268
68. PREFACE
The very friendly reception given to my previous book on the Inns and
Taverns of Pickwick has encouraged me to pursue the subject through
the other novels and writings of Dickens, and to compile the present
volume.
I do not claim that it is encyclopædic in the sense that it will be found
to supply a complete index to every inn mentioned in the novelist’s
books. Many a reader will recall, I expect, a certain inn in his favourite
story which has been overlooked; but, while my chief aim has been to
deal with the famous and prominent ones, I have not ignored the minor
ones which, in many cases, are also the most alluring, and often play
an important part in the story.
The plan has been to take the long novels in something approximating
to chronological order, followed by the shorter stories and sketches;
and, where an inn is mentioned in more than one book, to deal with it
fully in the chapter devoted to the story in which it was first alluded to.
Inns associated with the novelist’s own life find no place in this volume,
unless they have association also with his books.
In such a volume as this it is obviously necessary to quote freely from
Dickens’s books, but, when one recalls the young person’s comment on
lectures about Dickens that “she always loved them because of the
quotations,” no apology or excuse is needed here.
I am greatly indebted to my friends T. W. Tyrrell and Charles G. Harper
for much valuable advice and assistance in my task. The former has
kindly loaned me prints from his unique collection of topographical
photographs, and has also given me the advantage of his expert
knowledge of the subject.
69. How much I owe to the latter goes without saying. No one can write of
old inns, old coaches, or old coaching roads without acknowledging
indebtedness to the score of books standing in Mr. Harper’s name,
which are rich mines for any student of the subject quarrying for facts.
He has not only permitted me to dig in his mines, but has allowed also
the use of many of his charming drawings.
Acknowledgment is also made to Messrs. A. & C. Black, Messrs.
Methuen & Co., and the proprietors of the Cheshire Cheese for the use
of blocks on pages 24, 99 and 180 respectively.
B. W. MATZ.
DICKENSIAN INNS & TAVERNS
70. I
CHAPTER I
Dickens and Inns
N these days when life is, for the most part, and for most of us, a
wearying process of bustle and “business,” it is comforting as well as
pleasant to reflect that the old coaching inn still remains in all its quiet
grandeur and the noble dignity which quaint customs and unbroken
centuries of tradition have given to it. For a brief period in our recent
history, it seemed that even so great a British institution as the old
English inn, and its first cousin the tavern, were doomed to pass away.
Indeed, the invention of railways, followed by the almost automatic
suspension of the coach as a means of locomotion, did succeed actually
in closing down many of them. But the subsequent invention of the
motor-car reopened England’s highways and by-ways so that to-day
there are unmistakable indications that the old English inn is once more
acquiring that atmosphere of friendly hospitality and utility with which it
was endowed in the past, and which is so faithfully reflected in every
book of Dickens.
No one can really believe that the palatial and gilded hotels that sprang
up in the place of scores of the old coaching inns possessed the same
snug cheerfulness, the same appeal to the traveller, as did the old
hostelries of the coaching era. To-day, this is being realised more and
more, and when the time comes, as we are told is not far off, when
everyone will have his own motor-car, mine host of every wayside inn
and county town hostelry will once again become the prominent figure
that Dickens made him. The real romance of the coaching era may
never return. Perhaps we have become too matter-of-fact for that. But
something approximating to the spirit and glamour of those days is
possible still for those who are content to undertake a motor journey
minus the feverish ambition for breaking speed records. In many an
71. old-world English village stands an old-world English inn, and when that
hour before sunset arrives that all travellers of the open road know—
the moment when a luxurious and healthy weariness overcomes us—
ah, well, be sure the right sort of inn awaits you if you deserve such
good fortune, and, when the time comes to fill pipes and sit at ease
before a blazing log-fire, what better subject for your dreams will you
find than the glowing pages of a Dickens book?
In them you get not only the romance and the glamour of the journey
from place to place, but also descriptive pictures of the various inns, of
their picturesque outward appearances, of their interior comfort and
customs, of their glorious and luscious array of wholesome food and
wine, to say nothing of the wonderful description of the happy company
assembled there, all told with that incomparable charm and grace and
good humour of a writer of genius.
Dickens not only knew how to describe an inn and its comforts (and its
discomforts, too, sometimes), but he seemed to revel in doing so, and
became filled with delight when he was one of the guests within its
walls.
He seems to have shared Dr. Johnson’s view that there was no private
house in which people could enjoy themselves so well as at a good
tavern, where there was general freedom from anxiety, and where you
were sure of a welcome; and to agree with him that there is nothing as
yet contrived by man by which so much happiness is produced as in a
good tavern or inn.
His books are full of the truth of this, and provide many such happy
occasions when, after a cold coach drive, the hospitable host conducts
the passengers to a large room made cosy with a roaring fire, and
drawn curtains, and presenting an inviting spread of the good things of
life, and a plentiful supply of the best wines or a bowl of steaming
punch, for the jovial company. And the coach journey which brings one
to these inns! Is there any described with so much exhilaration to be
found elsewhere? Take the coach ride of Nicholas Nickleby along the
Great North Road to his destination in Yorkshire. Here is reflected the
real spirit of old-time travelling which brings us in touch with the old
customs of the coaching age in a manner that no historian could
72. possibly convey so realistically. Read again Tom Pinch’s ride to London.
We not only encounter old inns and old houses with their cherished
memories, their old rooms, each with its own romantic atmosphere and
a tale to tell, but we traverse picturesque by-ways and highways, which
in themselves recall the past as well as reveal unchanging scenes of
glorious nature; we can experience these feelings to-day in a way our
fathers could not. The railroad, for a spell, made this impossible. To-day
the road has come into its own again, and the motor-car brings back to
us the glory of the road, the pleasure of the inn, and the enjoyment of
the wonderful country which is England.
There seems to have been a positive allurement about an inn or tavern
for Dickens which he could not resist. He lingered over the most
decrepit and lowly public-house, such as the dirty Three Cripples, the
resort of Bill Sikes, as he did over the sumptuous Pavilion Hotel at
Folkestone. A wayside inn was as real a joy to him in its modest way as
was the chief coaching hotel in a country town with its studied comfort.
When travelling about the country himself with his friends, some
comment or pen-picture of the inn they stayed at creeps into his letters,
as it would seem, by instinct. Even in his unpublished diary we see
noted items about delightfully beautiful drives, coach offices, stage-
coaches, and excellent inns. And, when he and Wilkie Collins went for
their idle tour, it resolved itself into visiting the inns and coast corners in
out-of-the-way places.
His knowledge of inns was stupendous. In that Christmas story, “The
Holly Tree,” there are scores of them recalled, each recollection no
doubt reminiscent of experiences and association.
One gets a gleam of the joy he experiences at such times in the extract
from a letter to an American friend, in 1842, after he had gone for a
trip into Cornwall with some bright and merry companions:
“If you could but have seen one gleam of the bright fires by which we
sat at night in the big rooms of the ancient inns, or smelt but one
steam of the hot punch which came in every evening in a huge broad
china bowl!”
73. But instances could be multiplied.
Dickens saw something different in every inn, and succeeded in
conveying it to the reader. There were no two inns alike to him. Each
had its own tale to tell, its own individuality to reveal, its own
atmosphere and fare to present, whatever its grade or social
environment. As for an inn sign, it transported him into his most
whimsical and pleasant of moods.
In the following pages an attempt has been made to gather together
the material from his books which shows how Dickens delighted in
everything appertaining to inns, and how he extracted from association
with them all that glow of sentiment and joy which permeated their
atmosphere in the old days, leaving their pictures in glowing words for
all time.
There is nothing so calculated to make a place famous as mention of it
in a classic story. It may have already had a past history by association
with notable names and events, which gave it prominence in our annals
for a time; but in the case of a building, when it is demolished, it soon
passes out of memory. If, however, Dickens has drawn a pen-picture of
it, or, in the case of an old inn, has used it for a scene in one of his
books, it can never be forgotten; even when razed to the ground its
fame survives, and the site becomes a Dickens landmark.
74. T
CHAPTER II
Oliver Twist
THE RED LION, BARNET—THE ANGEL, ISLINGTON—THE COACH AND
HORSES, ISLEWORTH—THE THREE CRIPPLES—THE GEORGE INN—THE
EIGHT BELLS, HATFIELD
HERE are not many inns that can be identified in Oliver Twist, and
those that can play very little part in the enactment of the story, or
have any notable history to relate in regard to them. The first one to
attract attention is that at Barnet, where the Artful Dodger took Oliver
Twist for breakfast on the morning they encountered each other on the
latter’s tramp to London.
Although Dickens does not name this inn, we believe he had in mind
the Red Lion, for it was one of those inns that was an objective when
he and his friends went for a horse-ride out into the country. One such
occasion was chosen when his eldest daughter, Mamie, was born, in
March, 1838. He invited Forster to celebrate the event by a ride “for a
good long spell,” and they rode out fifteen miles on the Great North
Road. After dining at the Red Lion, in Barnet, on their way home, they
distinguished the already memorable day, as Forster tells us, by
bringing in both hacks dead lame.
This trip along the Great North Road was a favourite one, and Dickens
consequently became well acquainted with the highway. At the time of
Forster’s specific reference to the Red Lion, Dickens was engaged on
the early chapters of Oliver Twist, and we find him describing the
district in those pages wherein particular mention is made of Barnet.
Tramping to London after leaving Mr. Sowerberry, the undertaker, Oliver,
on the seventh morning, “limped slowly into the little town of Barnet,”
75. we are told. “The windows,” Dickens proceeds, “were closed; the street
was empty; not a soul was awakened to the business of the day.” Oliver,
with bleeding feet, and covered with dust, sat upon a doorstep. For
some time he wondered “at the great number of public houses (every
other house in Barnet was a tavern, large or small), gazing listlessly at
the coaches as they passed through.” Here he was discovered by Jack
Dawkins, otherwise the Artful Dodger, who, taking pity on him, assisted
him to rise, escorted him to an adjacent chandler’s shop, purchased
some ham and bread, and the two adjourned finally into a public-house
tap-room, to regale themselves prior to continuing their journey to
London. As the Red Lion was so familiar to Dickens, we may assume
that this was the inn to which he referred.
The inn, no doubt, was the same from which Esther Summerson, in
Bleak House, hired the carriage to drive to Mr. Jarndyce’s house, near
St. Albans. Arriving at Barnet, Esther, Ada and Richard found horses
waiting for them, “but, as they had only just been fed, we had to wait
for them, too,” she said, “and got a long fresh walk over a common and
an old battle-field, before the carriage came up.” Doubtless the posting-
house where this change was made was the Red Lion, for Dickens had
used it for posting his own horse many a time.
It is there to-day, and drives a busy trade, more as a suburban hostelry
than as a posting-inn.
Continuing their walk to London, the Artful Dodger and Oliver gradually
reached Islington, and entered the City together. Islington in days gone
by was a starting point for the mail-coaches going to the north, and as
a consequence was famous for its old inns. Perhaps the most famous,
particularly from the antiquarian standpoint, was the old Queen’s Head,
a perfect specimen of ancient domestic architecture, which was
destroyed in 1829. Another was, of course, the Angel; but the house
bearing that name to-day can claim none of the romance or
attractiveness of its ancient predecessor, and has recently been
modernised on the lines adopted by a very modern firm of caterers. But
the Angel of its palmy days was well-known to Dickens, and, although
he does not make it the scene of any prominent incident in his books, it
has mention in Oliver Twist in the chapter describing Oliver’s trudge to
76. London. It was nearly eleven o’clock when he and the Artful Dodger
reached the turnpike at Islington. They then crossed from the Angel
into St. John’s Road, on their way to the house near Field Lane, where
Oliver was dragged in and the door closed behind him.
THE RED LION, BARNET
Photograph by T. W. Tyrrell
The inn is mentioned again in the same book on the occasion when
Noah Claypole and Charlotte traversed the same road. “Mr. Claypole,”
we read, “went on, without halting, until he arrived at the Angel, at
Islington, where he wisely judged, from the crowd of passengers and
number of vehicles, that London began in earnest.” He, too, led the way
into St. John’s Road.
The Angel has been a London landmark for over two centuries. There
have been at least three houses of the same name, but the one Dickens
77. knew and referred to was apparently that built after the destruction in
1819 of the original.
In those days, it was the first halting-place, after leaving London, of
coaches bound along the Holyhead and Great North Roads. The original
house presented the usual features of a large old country inn, and “the
inn yard, approached by a gateway in the centre, was nearly a
quadrangle, with double galleries, supported by plain columns and
carved pilasters, with caryatides and other figures.” Now, as we have
said, it is merely a very ordinary, everyday modern refreshment house.
The low public-house in the “filthiest” part of Little Saffron Hill, in
whose dark and gloomy den, known as the parlour, was frequently to
be found Bill Sikes and his dog, Bull’s-Eye, probably was no particular
public-house so far as the novelist was concerned, although he gave it
the distinguishing name of the Three Cripples. At any rate, it has not
been identified, and must be assumed to be typical of the many with
which this district at one time was infested. First referred to in Chapter
XV, it is more minutely described in Chapter XXVI. “The room,” we are
told, “was illuminated by two gas-lights, the glare of which was
prevented by the barred shutters and closely drawn curtains of faded
red from being visible outside. The ceiling was blackened, to prevent its
colour from being injured by the flaring lamps; and the place was so full
of dense tobacco smoke that at first it was scarcely possible to discern
anything more. By degrees, however, as some of it cleared away,
through the open door, an assemblage of heads, as confused as the
voices that greeted the ear, might be made out; and, as the eye grew
more accustomed to the scene, the spectators gradually became aware
of the presence of a numerous company, male and female, crowded
round a long table, at the upper end of which sat a showman with a
hammer of office in his hands, while a professional gentleman with a
bluish nose, and his face tied up for the benefit of a toothache,
presided at a jingling piano in a remote corner.” That was a scene
common to the “low public-house,” of which the Three Cripples was a
notorious example, and the atmosphere depicted no doubt applied
generally to most of them.
78. THE COACH AND HORSES, ISLEWORTH
Drawn by C. G. Harper
On the other hand, the Coach and Horses, at Isleworth, where Bill Sikes
and Oliver alighted from the cart they had “begged a lift” in, is no flight
of Dickens’s imagination and can be discovered to-day exactly where he
located it.
The tramp of the two from Spitalfields to Chertsey on the burglary
expedition can easily be followed from Dickens’s clearly indicated
itinerary. The point on the journey where they obtained their lift in a
cart bound for Hounslow was near Knightsbridge. Having bargained
with the driver to put them down at Isleworth, they at length alighted a
little way beyond “a public-house called the Coach and Horses, which
stood at the corner of a road just beyond Isleworth leading to
Hampton.” They did not enter this public-house, but continued their
journey. Mr. John Sayce Parr, in an article in The Dickensian, Vol. I,
page 261, speaks of the topographical accuracy of Dickens in this
instance: “The literary pilgrim,” he says, “sets out to follow the route he
79. indicates, doubtful if he will find the places mentioned. There is,
however, not the slightest excuse for making mistakes, for Dickens
apparently visited the scenes and described them with the accuracy of
a guide-book. Thus, one finds the Coach and Horses, sure enough, at
the point where Brentford ends and Isleworth begins, by the entrance
to Sion Park, and near the spot where the road rambles off to the left.”
THE “EIGHT BELLS” Hatfield
Drawn by F. G. Kitton
The Coach and Horses, the same writer says, is not a picturesque inn.
It is a huge four-square lump of a place, and wears, indeed, rather a
dour and forbidding aspect. It is unquestionably the house of which
Dickens speaks, and was built certainly not later than the dawn of the
nineteenth century.
80. It still exists to-day, although the surroundings have altered somewhat
by the advent of the electric tramways and other “improvements.”
The George Inn, mentioned in Chapter XXXIII, where Oliver took the
letter for Mr. Losberne to be sent by “an express on horseback to
Chertsey,” cannot be identified, as the market-town in whose market-
place it stood is not mentioned or hinted at. Mr. Percy FitzGerald claims
that the description applies to Chertsey, but, as the letter had to be
taken to Chertsey, something seems wrong in his deduction.
In the chapter describing the flight of Bill Sikes, we read that, on
leaving London behind, he shaped his course for Hatfield. “It was nine
o’clock at night when the man, quite tired out, and the dog, limping
and lame from the unaccustomed exercise, turned down the hill by the
church of the quiet village, and, plodding along the little street, crept
into a small public-house whose scanty light had guided them to the
spot. There was a fire in the tap-room, and some of the country
labourers were drinking before it. They made room for the stranger, but
he sat down in the farthest corner, and ate and drank alone, or rather
with his dog, to whom he cast a morsel of food from time to time.”
Here he met the pedlar with his infallible composition for removing
blood-stains. This particular public-house is no doubt the Eight Bells, a
picturesque old house which still remains on the spot where Dickens
accurately located it. It is a quaint little building with a red-tiled roof
and dormer windows, and local tradition assigns it as that at which Bill
Sikes sought refuge for a short time before continuing his journey to St.
Albans, enabling Hatfield to claim it as a veritable Dickens landmark,
together with that other, the churchyard, where Mrs. Lirriper’s husband
was buried.
81. T
CHAPTER III
Nicholas Nickleby
THE SARACEN’S HEAD, SNOW HILL
HE Saracen’s Head Inn, Snow Hill, long since demolished, is familiar
to all readers of Nicholas Nickleby, because it was the hotel from
which Squeers took coach with his boys for Dotheboys Hall; and, but
for the fact, the name of Saracen’s Head would recall little or nothing to
the ordinary Londoner.
It stood on Snow Hill or Snore Hill, as it was called in the very early
days, and its exact location was two or three doors from St. Sepulchre’s
Church, down the hill, and was one of London’s oldest and most historic
inns, dating back to the 12th century. The first mention of it that we
can find is in a volume by John Lydgate, the Benedictine monk who
flourished in the early part of the 15th century, who is best
remembered by his poem, “The London Lyckpenny.” He tells the story
of the origin of the name, which is interesting as fixing an early date at
which the inn existed; even if it cannot be vouched for as correct in
face of the fact that others have been suggested, it is at least as
plausible.
It would appear that, when Richard Cœur-de-Lion returned from the
Third Crusade in 1194, he approached the city of London and entered it
by the New Gate, on the west. Being much fatigued by his long journey,
the weary monarch, on arriving at Snow Hill, outside the gate, stopped
at an inn there and called loudly to a tapster for refreshment. He drank
rather freely, “untille ye hedde of ye Kinge did swimme ryghte royallie.”
He then began laying about him right and left with a battle-axe, to the
“astoundmente and dyscomfythure of ye courtierres.” Upon which one
of the Barons said, “I wish hys majestie hadde ye hedde of a Saracen
82. before hym juste now, for I trowe he woulde play ye deuce wyth itte.”
Thereupon the King paid all the damage and gave permission that the
inn should be called “Ye Saracen’s Hedde.”
It is a pretty story, and, as we have suggested, may or may not be
true; but it gives us a starting point in the history of the inn. How long
before this incident the inn had existed and what its name was
previously, we cannot say.
Lydgate refers to the inn’s name again in the following stanza of one of
his poems:
Richarde hys sonne next by successyon,
Fyrst of that name—strong, hardy and abylle—
Was crowned Kinge, called Cuer de Lyon,
With Sarasenys hedde served at hys tabyelle.
The inn, by virtue of its situation, was in the centre of many an historic
event enacted in the surrounding streets, and would naturally be the
resort of those taking part in them. If records existed, many a thrilling
tale could be gathered from their perusal; as it is, only meagre details
can be furnished.
In 1522, Charles V of Germany, when on his visit to London, stayed at
the inn, and his retinue occupied three hundred beds, whilst stabling for
forty horses was needed also; evidence that it was no mean hostelry, in
spite of the fact that Stow’s record of the inn’s existence in his “Survey
of London” is confined to the following sentence:
“Hard by St. Sepulchre’s Church is a fayre and large inn for the receipt
of travellers, and hath to signe the ‘Saracen’s Head.’”
A few years later (1617) we get another reference to the hostel, in Wm.
Fennor’s “The Comptor’s Commonwealth,” a book describing the
troubles of an unfortunate debtor in the hands of serjeants and gaolers.
Therein is an allusion to a serjeant “with a phisnomy much resembling
the ‘Saracen’s Head,’ without Newgate,” alluding, of course, to the
figurehead on the sign-board of the inn.
83. Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
More than just a book-buying platform, we strive to be a bridge
connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.
Join us on a journey of knowledge exploration, passion nurturing, and
personal growth every day!
ebookbell.com