0% found this document useful (0 votes)
32 views59 pages

(Ebook) Programming Android by Zigurd Mednieks, Laird Dornin, G. Blake Meike, Masumi Nakamura ISBN 1449389694

The document promotes the ebook 'Programming Android' by Zigurd Mednieks and others, providing links to download it and other related ebooks. It includes ISBN numbers and additional resources for Android programming. The document also outlines the structure and content of the book, covering various aspects of Android development.

Uploaded by

jeydonjuuka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views59 pages

(Ebook) Programming Android by Zigurd Mednieks, Laird Dornin, G. Blake Meike, Masumi Nakamura ISBN 1449389694

The document promotes the ebook 'Programming Android' by Zigurd Mednieks and others, providing links to download it and other related ebooks. It includes ISBN numbers and additional resources for Android programming. The document also outlines the structure and content of the book, covering various aspects of Android development.

Uploaded by

jeydonjuuka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 59

Visit ebooknice.

com to download the full version and


explore more ebooks or textbooks

(Ebook) Programming Android by Zigurd Mednieks,


Laird Dornin, G. Blake Meike, Masumi Nakamura ISBN
1449389694

_____ Click the link below to download _____


https://ebooknice.com/product/programming-android-2405774

Explore and download more ebooks or textbooks at ebooknice.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

(Ebook) Blake, Nakamura Masumi. Programming Android, 2nd Edition by


Mednieks Zigurd, Dornin Laird, Meike G. ISBN 9781449316648,
9781348682639, 1348682639, 1449316646

https://ebooknice.com/product/blake-nakamura-masumi-programming-
android-2nd-edition-6400430

(Ebook) Programming Android: Java Programming for the New Generation


of Mobile Devices by Zigurd Mednieks, Laird Dornin, G. Blake Meike,
Masumi Nakamu ISBN 9781449316648, 1449316646

https://ebooknice.com/product/programming-android-java-programming-
for-the-new-generation-of-mobile-devices-2611638

(Ebook) Android Application Development: Programming with the Google


SDK by Rick Rogers, John Lombardo, Zigurd Mednieks, G. Blake Meike
ISBN 9780596521479, 0596521472

https://ebooknice.com/product/android-application-development-
programming-with-the-google-sdk-1564670

(Ebook) Biota Grow 2C gather 2C cook by Loucas, Jason; Viles, James


ISBN 9781459699816, 9781743365571, 9781925268492, 1459699815,
1743365578, 1925268497

https://ebooknice.com/product/biota-grow-2c-gather-2c-cook-6661374
(Ebook) Matematik 5000+ Kurs 2c Lärobok by Lena Alfredsson, Hans
Heikne, Sanna Bodemyr ISBN 9789127456600, 9127456609

https://ebooknice.com/product/matematik-5000-kurs-2c-larobok-23848312

(Ebook) SAT II Success MATH 1C and 2C 2002 (Peterson's SAT II Success)


by Peterson's ISBN 9780768906677, 0768906679

https://ebooknice.com/product/sat-ii-success-
math-1c-and-2c-2002-peterson-s-sat-ii-success-1722018

(Ebook) Programming Android with Kotlin: Achieving Structured


Concurrency with Coroutines by Pierre-Olivier Laurence, Amanda
Hinchman-Dominguez, G. Blake Meike, Mike Dunn ISBN 9781492063001,
1492063002
https://ebooknice.com/product/programming-android-with-kotlin-
achieving-structured-concurrency-with-coroutines-36877344

(Ebook) Master SAT II Math 1c and 2c 4th ed (Arco Master the SAT
Subject Test: Math Levels 1 & 2) by Arco ISBN 9780768923049,
0768923042

https://ebooknice.com/product/master-sat-ii-math-1c-and-2c-4th-ed-
arco-master-the-sat-subject-test-math-levels-1-2-2326094

(Ebook) Cambridge IGCSE and O Level History Workbook 2C - Depth Study:


the United States, 1919-41 2nd Edition by Benjamin Harrison ISBN
9781398375147, 9781398375048, 1398375144, 1398375047

https://ebooknice.com/product/cambridge-igcse-and-o-level-history-
workbook-2c-depth-study-the-united-states-1919-41-2nd-edition-53538044
Programming Android
Programming Android

Zigurd Mednieks, Laird Dornin, G. Blake Meike,


and Masumi Nakamura

Beijing • Cambridge • Farnham • Köln • Sebastopol • Tokyo


Programming Android
by Zigurd Mednieks, Laird Dornin, G. Blake Meike, and Masumi Nakamura

Copyright © 2011 Zigurd Mednieks, Laird Dornin, G. Blake Meike, and Masumi Nakamura. All rights
reserved.
Printed in the United States of America.

Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.

O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions
are also available for most titles (http://my.safaribooksonline.com). For more information, contact our
corporate/institutional sales department: (800) 998-9938 or [email protected].

Editors: Andy Oram and Brian Jepson Indexer: Lucie Haskins


Production Editor: Adam Zaremba Cover Designer: Karen Montgomery
Copyeditor: Audrey Doyle Interior Designer: David Futato
Technical Editors: Vijay S. Yellapragada and Johan Illustrator: Rebecca Demarest
van der Hoeven
Proofreader: Sada Preisch

Printing History:
July 2011: First Edition.

Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’Reilly Media, Inc. Programming Android, the image of a pine grosbeak, and related trade dress are
trademarks of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a
trademark claim, the designations have been printed in caps or initial caps.

While every precaution has been taken in the preparation of this book, the publisher and authors assume
no responsibility for errors or omissions, or for damages resulting from the use of the information con-
tained herein.

ISBN: 978-1-449-38969-7

[LSI]

1310671393
Table of Contents

Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii

Part I. Tools and Basics

1. Your Toolkit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Installing the Android SDK and Prerequisites 3
The Java Development Kit (JDK) 4
The Eclipse Integrated Development Environment (IDE) 5
The Android SDK 7
Adding Build Targets to the SDK 8
The Android Development Toolkit (ADT) Plug-in for Eclipse 9
Test Drive: Confirm That Your Installation Works 12
Making an Android Project 12
Making an Android Virtual Device (AVD) 16
Running a Program on an AVD 19
Running a Program on an Android Device 20
Troubleshooting SDK Problems: No Build Targets 21
Components of the SDK 21
The Android Debug Bridge (adb) 21
The Dalvik Debug Monitor Server (DDMS) 21
Components of the ADT Eclipse Plug-in 23
Android Virtual Devices 25
Other SDK Tools 26
Keeping Up-to-Date 28
Keeping the Android SDK Up-to-Date 28
Keeping Eclipse and the ADT Plug-in Up-to-Date 29
Keeping the JDK Up-to-Date 29
Example Code 30
SDK Example Code 30
Example Code from This Book 30
On Reading Code 32

v
2. Java for Android . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Android Is Reshaping Client-Side Java 33
The Java Type System 34
Primitive Types 34
Objects and Classes 35
Object Creation 35
The Object Class and Its Methods 37
Objects, Inheritance, and Polymorphism 39
Final and Static Declarations 41
Abstract Classes 45
Interfaces 46
Exceptions 48
The Java Collections Framework 52
Garbage Collection 55
Scope 56
Java Packages 56
Access Modifiers and Encapsulation 57
Idioms of Java Programming 59
Type Safety in Java 59
Using Anonymous Classes 62
Modular Programming in Java 65
Basic Multithreaded Concurrent Programming in Java 68
Synchronization and Thread Safety 68
Thread Control with wait() and notify() Methods 71
Synchronization and Data Structures 73

3. The Ingredients of an Android Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75


Traditional Programming Models Compared to Android 75
Activities, Intents, and Tasks 77
Other Android Components 78
Service 79
Content Providers 79
BroadcastReceiver 82
Static Application Resources and Context 82
Application Manifests 83
A Typical Source Tree 84
Initialization Parameters in AndroidManifest.xml 84
Resources 87
The Android Application Runtime Environment 88
The Dalvik VM 89
Zygote: Forking a New Process 89
Sandboxing: Processes and Users 89
Component Life Cycles 90

vi | Table of Contents
The Activity Life Cycle 90
Packaging an Android Application: The .apk File 92
On Porting Software to Android 93

4. Getting Your Application into Users’ Hands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95


Application Signing 95
Public Key Encryption and Cryptographic Signing 95
How Signatures Protect Software Users, Publishers, and
Secure Communications 97
Signing an Application 98
Placing an Application for Distribution in the Android Market 105
Becoming an Official Android Developer 106
Uploading Applications in the Market 106
Getting Paid 107
Google Maps API Keys 108
Specifying API-Level Compatibility 109
Compatibility with Many Kinds of Screens 109
Testing for Screen Size Compatibility 110
Resource Qualifiers and Screen Sizes 110

5. Eclipse for Android Software Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111


Eclipse Concepts and Terminology 112
Plug-ins 112
Workspaces 113
Java Environments 114
Projects 115
Builders and Artifacts 115
Extensions 115
Associations 117
Eclipse Views and Perspectives 117
The Package Explorer View 118
The Task List View 118
The Outline View 119
The Problems View 120
Java Coding in Eclipse 120
Editing Java Code and Code Completion 120
Refactoring 121
Eclipse and Android 122
Preventing Bugs and Keeping Your Code Clean 122
Static Analyzers 123
Applying Static Analysis to Android Code 127
Limitations of Static Analysis 130
Eclipse Idiosyncrasies and Alternatives 130

Table of Contents | vii


6. Effective Java for Android . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
The Android Framework 133
The Android Libraries 133
Extending Android 135
Organizing Java Source 140
Concurrency in Android 142
AsyncTask and the UI Thread 143
Threads in an Android Process 154
Serialization 156
Java Serialization 157
Parcelable 159
Classes That Support Serialization 162
Serialization and the Application Life Cycle 163

Part II. About the Android Framework

7. Building a View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167


Android GUI Architecture 167
The Model 167
The View 168
The Controller 169
Putting It Together 169
Assembling a Graphical Interface 171
Wiring Up the Controller 176
Listening to the Model 178
Listening for Touch Events 183
Listening for Key Events 186
Alternative Ways to Handle Events 187
Advanced Wiring: Focus and Threading 189
The Menu 193

8. Fragments and Multiplatform Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197


Creating a Fragment 198
Fragment Life Cycle 201
The Fragment Manager 202
Fragment Transactions 203
The Compatibility Package 208

9. Drawing 2D and 3D Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211


Rolling Your Own Widgets 211
Layout 212
Canvas Drawing 217

viii | Table of Contents


Drawables 228
Bitmaps 232
Bling 234
Shadows, Gradients, and Filters 237
Animation 238
OpenGL Graphics 243

10. Handling and Persisting Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247


Relational Database Overview 247
SQLite 248
The SQL Language 248
SQL Data Definition Commands 249
SQL Data Manipulation Commands 252
Additional Database Concepts 254
Database Transactions 255
Example Database Manipulation Using sqlite3 255
SQL and the Database-Centric Data Model for Android Applications 258
The Android Database Classes 259
Database Design for Android Applications 260
Basic Structure of the SimpleVideoDbHelper Class 261
Using the Database API: MJAndroid 264
Android and Social Networking 264
The Source Folder (src) 265
Loading and Starting the Application 267
Database Queries and Reading Data from the Database 267
Modifying the Database 271

Part III. A Skeleton Application for Android

11. A Framework for a Well-Behaved Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279


Visualizing Life Cycles 280
Visualizing the Activity Life Cycle 280
Visualizing the Fragment Life Cycle 292
The Activity Class and Well-Behaved Applications 295
The Activity Life Cycle and the User Experience 296
Life Cycle Methods of the Application Class 296
A Flowing and Intuitive User Experience Across Activities 299
Multitasking in a Small-Screen Environment 299
Tasks and Applications 299
Specifying Launch and Task Behavior 300

Table of Contents | ix
12. Using Content Providers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
Understanding Content Providers 306
Implementing a Content Provider 307
Browsing Video with Finch 308
Defining a Provider Public API 309
Defining the CONTENT_URI 310
Creating the Column Names 312
Declaring Column Specification Strings 312
Writing and Integrating a Content Provider 314
Common Content Provider Tasks 314
File Management and Binary Data 316
Android MVC and Content Observation 318
A Complete Content Provider: The SimpleFinchVideoContentProvider
Code 319
The SimpleFinchVideoContentProvider Class and Instance Variables 319
Implementing the onCreate Method 321
Implementing the getType Method 322
Implementing the Provider API 322
Determining How Often to Notify Observers 327
Declaring Your Content Provider 327

13. Exploring Content Providers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329


Developing RESTful Android Applications 330
A “Network MVC” 331
Summary of Benefits 333
Code Example: Dynamically Listing and Caching YouTube
Video Content 334
Structure of the Source Code for the Finch YouTube Video Example 335
Stepping Through the Search Application 336
Step 1: Our UI Collects User Input 337
Step 2: Our Controller Listens for Events 337
Step 3: The Controller Queries the Content Provider with a managedQuery
on the Content Provider/Model 338
Step 4: Implementing the RESTful Request 338
Constants and Initialization 338
Creating the Database 339
A Networked Query Method 339
insert and ResponseHandlers 352
File Management: Storing Thumbnails 353

x | Table of Contents
Part IV. Advanced Topics

14. Multimedia . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359


Audio and Video 359
Playing Audio and Video 360
Audio Playback 361
Video Playback 363
Recording Audio and Video 364
Audio Recording 365
Video Recording 368
Stored Media Content 369

15. Location and Mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371


Location-Based Services 372
Mapping 373
The Google Maps Activity 373
The MapView and MapActivity 374
Working with MapViews 375
MapView and MyLocationOverlay Initialization 375
Pausing and Resuming a MapActivity 378
Controlling the Map with Menu Buttons 379
Controlling the Map with the Keypad 381
Location Without Maps 382
The Manifest and Layout Files 382
Connecting to a Location Provider and Getting Location Updates 383
Updating the Emulated Location 386

16. Sensors, NFC, Speech, Gestures, and Accessibility . . . . . . . . . . . . . . . . . . . . . . . . . . . 391


Sensors 391
Position 393
Other Sensors 395
Near Field Communication (NFC) 396
Reading a Tag 396
Writing to a Tag 403
P2P Mode 405
Gesture Input 406
Accessibility 407

17. Communication, Identity, Sync, and Social Media . . . . . . . . . . . . . . . . . . . . . . . . . . 411


Account Contacts 411
Authentication and Synchronization 414
Authentication 415

Table of Contents | xi
Synchronization 422
Bluetooth 429
The Bluetooth Protocol Stack 429
Bluez: The Linux Bluetooth Implementation 431
Using Bluetooth in Android Applications 431

18. The Android Native Development Kit (NDK) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445


Native Methods and JNI Calls 446
Conventions on the Native Method Side 446
Conventions on the Java Side 447
The Android NDK 448
Setting Up the NDK Environment 448
Compiling with the NDK 448
JNI, NDK, and SDK: A Sample App 449
Android-Provided Native Libraries 451
Building Your Own Custom Library Modules 453
Native Activities 456

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463

xii | Table of Contents


Preface

The purpose of this book is to enable you to create well-engineered Android applica-
tions that go beyond the scope of small example applications.
This book is for people coming to Android programming from a variety of backgrounds.
If you have been programming iPhone or Mac OS applications in Objective-C, you will
find coverage of Android tools and Java language features relevant to Android pro-
gramming that will help you bring your knowledge of mobile application development
to Android. If you are an experienced Java coder, you will find coverage of Android
application architecture that will enable you to use your Java expertise in this newly
vibrant world of client Java application development. In short, this is a book for people
with some relevant experience in object-oriented languages, mobile applications, REST
applications, and similar disciplines who want to go further than an introductory book
or online tutorials will take them.

How This Book Is Organized


We want to get you off to a fast start. The chapters in the first part of this book will
step you through using the SDK tools so that you can access example code in this book
and in the SDK, even as you expand your knowledge of SDK tools, Java, and database
design. The tools and basics covered in the first part might be familiar enough to you
that you would want to skip to Part II where we build foundational knowledge for
developing larger Android applications.
The central part of this book is an example of an application that uses web services to
deliver information to the user—something many applications have at their core. We
present an application architecture, and a novel approach to using Android’s frame-
work classes that enables you to do this particularly efficiently. You will be able to use
this application as a framework for creating your own applications, and as a tool for
learning about Android programming.
In the final part of this book, we explore Android APIs in specific application areas:
multimedia, location, sensors, and communication, among others, in order to equip
you to program applications in your specific area of interest.

xiii
By the time you reach the end of this book, we want you to have gained knowledge
beyond reference material and a walk-through of examples. We want you to have a
point of view on how to make great Android applications.

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, databases, data types, environment variables,
statements, and keywords
Constant width bold
Shows commands or other text that should be typed literally by the user
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: “Programming Android by Zigurd

xiv | Preface
Mednieks, Laird Dornin, G. Blake Meike, and Masumi Nakamura. Copyright 2011
O’Reilly Media, Inc., 978-1-449-38969-7.”
If you feel your use of code examples falls outside fair use or the permission given here,
feel free to contact us at [email protected].

Safari® Books Online


Safari Books Online is an on-demand digital library that lets you easily
search more than 7,500 technology and creative reference books and vid-
eos to find the answers you need quickly.
With a subscription, you can read any page and watch any video from our library online.
Read books on your cell phone and mobile devices. Access new titles before they are
available for print, and get exclusive access to manuscripts in development and post
feedback for the authors. Copy and paste code samples, organize your favorites, down-
load chapters, bookmark key sections, create notes, print out pages, and benefit from
tons of other time-saving features.
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/9781449389697
To comment or ask technical questions about this book, send email to:
[email protected]
For more information about our books, courses, conferences, and news, see our website
at http://www.oreilly.com.
Find us on Facebook: http://facebook.com/oreilly
Follow us on Twitter: http://twitter.com/oreillymedia

Preface | xv
Watch us on YouTube: http://www.youtube.com/oreillymedia

Acknowledgments
The authors have adapted portions of this book from their previously released title,
Android Application Development (O’Reilly).
Drafts of this book were released on the O’Reilly Open Feedback Publishing System
(OFPS) in order to get your feedback on whether and how we are meeting the goals for
this book. We are very grateful for the readers who participated in OFPS, and we owe
them much in correcting our errors and improving our writing. Open review of drafts
will be part of future editions, and we welcome your views on every aspect of this book.

xvi | Preface
PART I
Tools and Basics

Part I shows you how to install and use your tools, what you need to know about Java
to write good Android code, and how to design and use SQL databases, which are
central to the Android application model, persistence system, and implementation of
key design patterns in Android programs.
Random documents with unrelated
content Scribd suggests to you:
pleased to send him.

Adam has sinn’d: and on the ground


Shall thorns and thistles grow;
His body lies in dust; his soul—
Ah! whither shall it go?

Shall one who dared to disobey,


With God forever dwell?
When angels sinn’d God did not spare,
But cast them down to hell.

Yet long before the world was made


Our God contrived a plan,
By which his sinful soul to save,
And pardon guilty man.

The Father said his Son should die,


The Son replied, “I will:
A feeble body I will take;
This body men shall kill.”

Father, how great thy love to man,


To send thy Son from high!
How great thy love, O glorious Son,
To come, and bleed, and die!
LESSON XII.
THE VIRGIN MARY.
Luke, i. 26-55.

God told Adam and Eve that he would send his Son down some day
to die for them. But Adam and Eve did not love God; for they were
grown wicked.
Could God make them good?
Yes; he could: for there is the Holy Spirit in heaven, and the Holy
Spirit could come into them and make them good.
You know, my little children, we are wicked, and God can make us
good with his Holy Spirit. If God puts his Holy Spirit in us, we shall
not go to hell, and live with Satan.
I hope you will ask God to give you his Holy Spirit. Say to God, O
give me thy Holy Spirit, to make me good!
Adam had a great many children and grandchildren, and they had
more children; at last the world was full of people—more people
than you could count.
After Adam and Eve had been dead a long while, and when the
world was full of people, God said to his Son, Now, my beloved Son,
go down into the world.
But God chose that his Son should be a little baby at first—
because everybody is a little baby at first.
God sent his Son to be the baby of a poor woman. This woman’s
name was Mary. Mary had no little children. She was a good woman
and loved God. God’s Holy Spirit was in her, and made her meek and
gentle.
One day an angel came to her. When Mary saw the bright angel,
she was frightened: but the angel said, “Fear not, Mary; God loves
you. He will send you a baby, that shall be the Son of God. You shall
call his name Jesus. He will come to save people from Satan.”
Mary was much surprised at what the angel said. She thought she
was not good enough to have such a baby as the Lord Jesus.
When the angel was gone back to heaven, Mary sang a sweet
song of praise to God for his goodness.
Mary said, My soul praises God, and my spirit is glad because of
my Saviour.
Mary called her baby her Saviour, for she knew that he would
save her from hell.
I wonder not that Mary fear’d
When Gabriel to her appear’d:
How could she know he came to bring
So sweet a message from his King?

Full long the Son in heaven had stay’d


Since first the promise had been made
To shed his blood for Adam’s sin,
And happiness for man to win.

But yet the Son had ne’er forgot,


And what he said he changed not;
The time was come he should be born,
And in this world should live forlorn.

Mary shall be the mother dear,


Who in her arms the child shall bear;
The angel came this news to bring,
And Mary listen’d wondering.

And did the Lord a poor maid choose—


And all the great and rich refuse?
High honors God delights to place
On those who humbly seek his face.
LESSON XIII.
THE BIRTH OF JESUS.
Luke, ii. 1-7.

Mary had a husband called Joseph. He was a good man, and very
kind to Mary.
Now before Mary’s baby was born, a great king said that
everybody must have their names written down. So Mary and
Joseph left their house, and went a great way off. At last they came
to a town called Bethlehem.
It was night. Where could they sleep? They went to an inn, and
said, Do let us in. We have come from a great way off.
But the master of the inn said, I have no room in my inn for you.
What could poor Mary do? Must she sleep in the street? Mary said
she would sleep in the stable, if the master would let her.
So Mary and Joseph went into the stable. There were cows and
asses in the stable.
While Mary was in the stable, God sent her the little baby he had
promised her. She knew he was the Son of God, though he looked
like other little babies.
She wrapped him in some long clothes, called swaddling clothes;
but she had no cradle for him to sleep in, and she could not lay him
on the ground, lest the beasts should tread upon him; so she put
him in the manger, and she sat by him to take care of him.
How dearly Mary loved this sweet babe!
This baby had not a naughty heart, as other babies have. Jesus
had no sin, but was quite meek and lowly. Yet other babies have
cradles and soft pillows, while Jesus lay in a manger.
I will tell you a verse to say to your little baby brother when you
rock his cradle:

Soft and easy is thy cradle;—


Coarse and hard thy Saviour lay
When his birthplace was a stable,
And his softest bed was hay.
LESSON XIV.
THE SHEPHERDS.
Luke, ii. 8-20.

There were some fields near Bethlehem. On the night when Jesus
was born, some shepherds were sitting by their sheep in those
fields. Why did they sit up at night? To keep their sheep from the
wolves and lions which walk about at night. There are no lions
where we live, but near Bethlehem there were some.
These shepherds saw a great light. A beautiful angel came from
heaven. The poor shepherds were afraid; but the angel said, Fear
not, I have sweet news to tell you. God has sent his own Son from
heaven to save you from hell. He is a baby now, lying in a manger.
Go to Bethlehem, and you will find him.
When the angel had done speaking, hundreds and hundreds of
bright angels filled the sky, and began singing and praising God for
having sent his Son to save men.
At last the angels went back to heaven, and the shepherds were
left alone.
Did they stay with their sheep? No; they said, Let us go and see
the Son of God.
They ran to Bethlehem, and went to the stable of the inn. There
was a babe in the manger; Mary and Joseph were sitting by. The
shepherds said, This is the Son of God. Angels have spoken to us to-
night, and told us where to find him.
All the people in Bethlehem were much surprised when the
shepherds told them about the angels and the Son of God.
Blessed Babe! what glorious features!
Spotless, fair, divinely bright:
Must he dwell with brutal creatures?
How could angels bear the sight?

Was there nothing but a manger


Wretched sinners could afford,
To receive the heavenly stranger?
Did they thus affront the Lord?

See the kinder shepherds round him


Telling wonders from the sky;
Where they sought him, there they found him.
With his virgin mother by.

See the lovely babe a-dressing,


Lovely infant, how he smiled!
When he wept, the mother’s blessing
Sooth’d and hush’d the holy child.
LESSON XV.
THE WISE MEN.
Matthew ii.

There were some wise and rich men. They lived a great way from
Bethlehem. They knew that God had sent his Son to be a babe but
they did not know where to find him; so God put a beautiful star in
the sky, and God made it move toward the place where Jesus was.
So the wise men left their houses, and set out on a long journey;
but first they said, Let us bring some presents for the Son of God:
for he is a king. They took some gold, and some sweet-smelling stuff
to burn. They looked at the star as they went. At last it stopped over
a house in Bethlehem. The wise men were very glad indeed. They
longed to see the Son of God. They went in, and there they saw
Mary and her child Jesus: they fell down, and began to praise him,
and to call him the Son of God, and the King.
They took out their presents, and gave them to him. Mary was
poor; but now she had some money to buy things for her little baby.
LESSON XVI.
KING HEROD.
Matthew, ii. Luke, ii. 51, 52.

There was a very wicked king called Herod. He lived a little way from
Bethlehem. He heard that a babe was born in Bethlehem, and that
some people said that the babe was a king.
Now Herod did not like that there should be any other king
besides himself. Herod did not like that even the Son of God should
be king. So Herod said, I will kill this babe that is called a king.
Herod knew that this babe was in Bethlehem; but there were
many babes in Bethlehem, and Herod did not know which was the
babe that was called a king.
Some people knew which it was; but they loved Jesus, and they
would not tell Herod. A very wicked thought came into Herod’s mind.
He thought, I will kill all the babes in Bethlehem. Do you think God
would let Herod kill his Son? No. God knew what Herod meant to do.
God sent one of his bright angels to speak to Joseph when he was
asleep.
The angel said, A wicked king wants to kill the baby. Get up,
Joseph; take Mary and the baby a great way off. So Joseph got up
quickly; he took his ass, he put Mary on it, and she held the baby. It
was dark when they set off. Nobody saw them go.
The next morning some men came with swords. Herod had sent
them. They were come to kill all the babies. They opened every
door, and said, Is there a baby here? Then they snatched it from its
mother, and killed it, and the poor mother cried bitterly. Had you
walked down the streets, you would have heard nothing but women
weeping and crying out, My pretty babe is dead; I shall never see it
more!
Was Jesus killed?
No: he was gone far away. His Father, God, had sent him away.
Herod could not kill him, for God would not let him die so soon.
At last King Herod died. Then God sent an angel to speak to
Joseph when he was asleep. The angel said, Joseph, go back to your
own country; Herod is dead. So Joseph took the ass, and Mary, and
the sweet child, Jesus, and they all came back to their own country.
Joseph was a carpenter. Jesus lived with Joseph and Mary, and
minded all they said. He was a wise child, and loved to think of God.
God his Father loved him, and everybody loved him, because he was
so meek and kind. The older he grew the more they loved him.
LESSON XVII.
THE TEMPTATION.
Matthew iv. 1-11.

At last Jesus grew to be a man. He knew that he must go from place


to place, and teach people about God.
But first he went into a place by himself—called a wilderness. He
had no house to sleep in there, no friend to speak to, no food to eat.
In the night it was cold, in the day very hot.
There were no men, but there were lions, wolves and bears. At
night they roared and howled; but Jesus trusted in his Father.
He ate nothing for forty days and forty nights, God kept him alive.
When Jesus was alone, then he spoke in his heart to his dear Father.
At last someone came and spoke to him.
Who was it?
Not a man, not a bright angel, not God; it was Satan. I do not
know how he looked. He was come to tempt Jesus to do wickedly,
and not to mind God his Father. Satan knew that Jesus was hungry.
He said to him, Turn these stones into bread! but Jesus would not,
for God had promised to feed him himself.
After that, Satan took Jesus to the top of a great building, that
was much higher than a church. It is dreadful to be on the top of a
very high place; it makes one tremble to look down from the top.
Satan said to Jesus, Throw yourself down from this place; your
Father will send his angels to keep you from being hurt, for you
know that he has promised to take care of you.
Would Jesus have done right had he thrown himself down? No:
Jesus knew that his Father would be displeased if he threw himself
down; and Jesus always did the things that pleased his Father.
Then Satan took him to the top of a very high hill. He showed him
the most beautiful things in the world, gardens and houses, ships
and carriages, and fine clothes and feasts. He said, Look at these
fine things. I will give them all to you. You shall have all the world
for your own; only kneel down and call me God.
But Jesus said, I will pray to my Father, and not to you.
Jesus loved his Father better than all the things in the world.
Adam and Eve minded Satan, and disobeyed God; but Jesus did
all his Father had told him. Adam was disobedient, Jesus was
obedient.
Then Satan went away, and angels came from heaven and fed
Jesus.
Satan goes about, trying to make children naughty. A lion could
only eat your body, but Satan wants to have your soul and body in
hell. Satan hates you. He is your enemy. But God is stronger than
Satan. Say to God, Keep me from minding Satan, and God will keep
you.
Upon that mountain’s height
Two mighty princes stand;
Jesus the Prince of Light,
Satan at his right hand.
Below them lies the prospect fair
Of all earth holds of rich or rare.

Tables are seen around,


Spread with delicious meats;
Gardens where fruits abound,
And thousand tempting sweets:
Silver and gold and precious stones,
Chariots and palaces and thrones.

Satan did once prevail


On Eve to disobey:
And now why should he fail
To tempt the Lord astray?
For Eve abundant food possess’d,
While Christ with hunger is distress’d.

In vain the tempter tries


The Saviour to deceive,
For Jesus left the skies
Our misery to relieve:
His Father dear he sought to please,
Nor wish’d for earthly joy and ease.

He had seen brighter things,


And sweeter joys had known,
Where angels touch the strings
Around his Father’s throne.
And shall he from that throne descend
Before the evil one to bend?

No! He will hunger bear,


And suffer sharpest pain,
Till God shall hear his prayer,
And his weak life sustain.
And lo! ashamed the tempter flies,
And angels feed him from the skies.
LESSON XVIII.
THE TWELVE DISCIPLES.
Mark, i. 16-20.

When Jesus was a man, he began to teach people about his Father.
Jesus used to preach.
Where did he preach?
Sometimes he preached to people in a place like a church;
sometimes he preached in the fields; sometimes he sat on the top of
a hill and preached; and sometimes he sat in a ship, and the people
stood by the edge of the water to hear him. Jesus did not always
live in the same place: he used to walk about from one place to
another.
Did Jesus walk about alone? No; he had twelve friends always
with him. He called them his twelve disciples.
How many are twelve? Let us count the little children in this
room. Here are twelve. Jesus had just so many disciples.
One was called Peter, and another John, and another James, and
another Thomas. I will not tell you the names of all, lest you should
forget them.
Peter was a fisherman. He had a little ship, and he used to catch
fish in the day and in the night. James and John had another little
ship, and they used to catch fish.
One day Jesus passed by their ships, and Jesus saw Peter and his
brother Andrew throwing a net into the sea to catch fish, and Jesus
said to them, Come with me. And Peter and Andrew left their nets,
and their ships, and went with Jesus.
And Jesus went a little further, and he saw James and John sitting
in their ship, mending the holes in their nets, and Jesus said to
them, Come with me; and they left their nets and went with Jesus.
Jesus called what people he pleased to come with him.
Shall I tell you why Jesus chose to have twelve friends always
with him? What do you think was the reason?
Jesus wished to teach them about God his Father, that they might
teach other people about him. They liked being with him, and
listening to his words. Would you have liked to be always with
Jesus?
When Jesus was alone with his disciples, he used to tell them
secrets about God and heaven. They loved him very much indeed;
they called him Master, and Lord. Jesus loved them still more than
they loved him, and he called them his friends.
Jesus used to give them part of his things. But Jesus had no
house to live in, and he had very little money. Sometimes Jesus and
his friends were very much tired with walking far, and sometimes
they were very hungry and thirsty. But kind people often asked them
to come into their houses, and gave them food. Other people
laughed at Jesus, and called him names.
Were the disciples good?—They were bad like us; but Jesus put
his Spirit into them, and made them better. The disciples were not
quite good like Jesus; they often quarreled with each other, and
sometimes they were unkind to poor people.
How happy they who shared the bread
Of Jesus here below!
From place to place he traveled,
And they with him did go.

What though they never had a place


Where safely to abide,
They saw their loving Master’s face,
And followed by his side.

They heard him preach from hills and ships


Of things to men unknown;
But sweeter words dropped from his lips
When they were all alone;

For then he would the things explain


They could not understand,
That heav’nly wisdom they might gain,
And teach it through the land.

CHILD.
’Tis true I can not here below
With thee, my Saviour, dwell;
To heaven I one day hope to go,
And there to know thee well.
LESSON XIX.
THE FIRST MIRACLE.
John, ii. 1-11.

I told you that some people used to ask Jesus to come into their
houses. I shall now tell you of a man who did ask Jesus. This man
gave a feast, and Jesus came to the feast. Mary, the mother of
Jesus, came; and the disciples came. There were a great many more
people besides at the feast.
There was some wine for the people to drink: but there was so
little, that very soon it was all gone.
Jesus knew that the wine was gone. Could not Jesus give the
people more wine?—Yes; for he made the world and all things in it.
There were some large stone jars in the room. Jesus said to the
servants, Fill the jars with water, and they filled them quite full.
Then Jesus said, Take some, and give it to the master to drink.
The servants did so; but Jesus had turned the water into wine.
When the master had tasted it, he said, What nice wine this is!
Where did it come from?
The servants told him how Jesus had told them to fill the jars with
water. Then all the people at the feast knew that Jesus had turned
the water into wine.
This was the first wonder that Jesus did; it was called a miracle.
Why did Jesus do miracles? To show people that he was the Son
of God.
The disciples now felt quite sure that Jesus was the Son of God.

Once Jesus to a marriage went;


The numerous guests surround the board,
When lo! they find the wine is spent;—
This—Mary hears, and tells the Lord.

Before the guests’ astonished eyes


Christ makes his heavenly glory shine;
The thing desired he soon supplies.
And changes water into wine.

How ready does our Lord appear


Our fond desires to satisfy!
And all that we can wish for here
He is well able to supply.
LESSON XX.
SEVERAL MIRACLES.
Luke, vi. 11-16.

After Jesus had turned the water into wine, he did a great many
wonders. He made blind people see, and deaf people hear, and
dumb people speak, and lame people walk.
When Jesus came to a place, all the sick people crowded round
him.
Jesus did not send them away because they disturbed him, but
he cured them all—yes—every one.
This was the way in which he cured one blind man. He said, See!
and the man could see that moment.
This was the way in which he cured a man who was deaf and
dumb. Jesus put his fingers into his ears, and touched his tongue,
and looked up to his Father in heaven, and said, Be opened! and
immediately the string of his tongue was loosed, and he could speak
plainly.
Once Jesus saw a poor sick man lying on a bed, and Jesus said to
him, Should you like to be made well? The poor man said he wished
very much to be made well. Then Jesus said, Get up, carry your bed,
and walk. The man tried to get up, and he found that he could; for
Jesus gave him strength.
One day Jesus was in a place like a church; he was preaching;
when he saw a poor woman whose back was bent, so that she could
not lift up her head. Jesus said, Woman, I have made you well; and
then Jesus touched her with his hands, and her back grew straight,
and she began to praise God.
Sometimes Jesus made dead people alive again. That was more
wonderful than making sick people well.
Once Jesus was walking on the road. A great many people were
walking after him, for people liked to see him do wonders, and to
hear him talk. They met some men carrying a dead man to put him
in the ground.
A poor old woman came after, crying very much. She was the
mother of the dead man. He was her only son. Jesus was very sorry
to see her cry. He came up to her and said, Do not cry, and then he
touched the coffin. There was no top to it; the dead man was lying
in it.
Jesus said, Get up, young man. He sat up and began to speak.
Then Jesus said to his mother, Here is your son.
All the people were surprised, and said, This must be the Son of
God. He can make dead people live again.
LESSON XXI.
THE SINNER AND SIMON.
Luke, vii. 36 to end.

Why did Jesus come into the world?—To save us from hell.
But why did God say that people must go to hell?—Because
everybody was naughty.
Jesus can forgive people their naughtiness, and make them good.
But Jesus will not forgive people who are not sorry. I will tell you of
a proud man who was not sorry, and of a poor woman who was
sorry.
A rich proud man asked Jesus to come and dine with him. Why
did he ask Jesus? he did not love him;—he only asked him, that he
might hear him talk: but Jesus said he would come.
The proud man treated Jesus very unkindly. He gave him no
water to wash his feet, put no sweet ointment upon them, gave him
no kiss.
A poor woman, who had been very naughty, saw Jesus go into
the rich man’s house. She came up behind Jesus, and began to cry
for all her naughtiness. She knew Jesus could forgive her, and she
loved Jesus.
She had brought a box of ointment with her: she stooped down,
and her tears fell upon Jesus’ feet, and with her tears she washed
them: she wiped them with her long hair, and then poured the sweet
ointment upon them, and kissed them.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebooknice.com

You might also like