100% found this document useful (3 votes)
53 views

Android Studio Arctic Fox Essentials Java Edition Developing Android Apps Using Android Studio 202031 And Java 1st Edition Neil Smyth pdf download

The document is a comprehensive guide titled 'Android Studio Arctic Fox Essentials Java Edition' by Neil Smyth, focusing on developing Android applications using Android Studio 2020. It covers various topics including setting up the development environment, creating Android apps, using the AVD emulator, and understanding Android architecture and lifecycle. The book is intended for personal use and provides detailed instructions and examples for both beginners and experienced developers in Android app development.

Uploaded by

keistidjidda
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
100% found this document useful (3 votes)
53 views

Android Studio Arctic Fox Essentials Java Edition Developing Android Apps Using Android Studio 202031 And Java 1st Edition Neil Smyth pdf download

The document is a comprehensive guide titled 'Android Studio Arctic Fox Essentials Java Edition' by Neil Smyth, focusing on developing Android applications using Android Studio 2020. It covers various topics including setting up the development environment, creating Android apps, using the AVD emulator, and understanding Android architecture and lifecycle. The book is intended for personal use and provides detailed instructions and examples for both beginners and experienced developers in Android app development.

Uploaded by

keistidjidda
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/ 85

Android Studio Arctic Fox Essentials Java

Edition Developing Android Apps Using Android


Studio 202031 And Java 1st Edition Neil Smyth
download
https://ebookbell.com/product/android-studio-arctic-fox-
essentials-java-edition-developing-android-apps-using-android-
studio-202031-and-java-1st-edition-neil-smyth-35928982

Explore and download more ebooks at ebookbell.com


Android Studio Arctic Fox
Essentials
Java Edition
Android Studio Arctic Fox Essentials – Java Edition
ISBN-13: 978-1-951442-36-1
© 2021 Neil Smyth / Payload Media, Inc. All Rights Reserved.
is book is provided for personal use only. Unauthorized use, reproduction
and/or distribution strictly prohibited. All rights reserved.
e content of this book is provided for informational purposes only.
Neither the publisher nor the author o ers any warranties or representation,
express or implied, with regard to the accuracy of information contained in
this book, nor do they accept any liability for any loss or damage arising
from any errors or omissions.
is book contains trademarked terms that are used solely for editorial
purposes and to the bene t of the respective trademark owner. e terms
used within this book are not intended as infringement of any trademarks.
Rev: 1.0
Table of Contents
1. Introduction
1.1 Downloading the Code Samples
1.2 Feedback
1.3 Errata
2. Setting up an Android Studio Development Environment
2.1 System Requirements
2.2 Downloading the Android Studio Package
2.3 Installing Android Studio
2.3.1 Installation on Windows
2.3.2 Installation on macOS
2.3.3 Installation on Linux
2.4 e Android Studio Setup Wizard
2.5 Installing Additional Android SDK Packages
2.6 Making the Android SDK Tools Command-line Accessible
2.6.1 Windows 8.1
2.6.2 Windows 10
2.6.3 Linux
2.6.4 macOS
2.7 Android Studio Memory Management
2.8 Updating Android Studio and the SDK
2.9 Summary
3. Creating an Example Android App in Android Studio
3.1 About the Project
3.2 Creating a New Android Project
3.3 Creating an Activity
3.4 De ning the Project and SDK Settings
3.5 Modifying the Example Application
3.6 Modifying the User Interface
3.7 Reviewing the Layout and Resource Files
3.8 Adding Interaction
3.9 Summary
4. Creating an Android Virtual Device (AVD) in Android Studio
4.1 About Android Virtual Devices
4.2 Creating a New AVD
4.3 Starting the Emulator
4.4 Running the Application in the AVD
4.5 Running on Multiple Devices
4.6 Stopping a Running Application
4.7 Supporting Dark eme
4.8 Running the Emulator in a Tool Window
4.9 AVD Command-line Creation
4.10 Android Virtual Device Con guration Files
4.11 Moving and Renaming an Android Virtual Device
4.12 Summary
5. Using and Con guring the Android Studio AVD Emulator
5.1 e Emulator Environment
5.2 e Emulator Toolbar Options
5.3 Working in Zoom Mode
5.4 Resizing the Emulator Window
5.5 Extended Control Options
5.5.1 Location
5.5.2 Displays
5.5.3 Cellular
5.5.4 Battery
5.5.5 Camera
5.5.6 Phone
5.5.7 Directional Pad
5.5.8 Microphone
5.5.9 Fingerprint
5.5.10 Virtual Sensors
5.5.11 Snapshots
5.5.12 Record and Playback
5.5.13 Google Play
5.5.14 Settings
5.5.15 Help
5.6 Working with Snapshots
5.7 Con guring Fingerprint Emulation
5.8 e Emulator in Tool Window Mode
5.9 Summary
6. A Tour of the Android Studio User Interface
6.1 e Welcome Screen
6.2 e Main Window
6.3 e Tool Windows
6.4 Android Studio Keyboard Shortcuts
6.5 Switcher and Recent Files Navigation
6.6 Changing the Android Studio eme
6.7 Summary
7. Testing Android Studio Apps on a Physical Android Device
7.1 An Overview of the Android Debug Bridge (ADB)
7.2 Enabling ADB on Android-based Devices
7.2.1 macOS ADB Con guration
7.2.2 Windows ADB Con guration
7.2.3 Linux adb Con guration
7.3 Testing the adb Connection
7.4 Summary
8. e Basics of the Android Studio Code Editor
8.1 e Android Studio Editor
8.2 Splitting the Editor Window
8.3 Code Completion
8.4 Statement Completion
8.5 Parameter Information
8.6 Parameter Name Hints
8.7 Code Generation
8.8 Code Folding
8.9 Quick Documentation Lookup
8.10 Code Reformatting
8.11 Finding Sample Code
8.12 Live Templates
8.13 Summary
9. An Overview of the Android Architecture
9.1 e Android So ware Stack
9.2 e Linux Kernel
9.3 Android Runtime – ART
9.4 Android Libraries
9.4.1 C/C++ Libraries
9.5 Application Framework
9.6 Applications
9.7 Summary
10. e Anatomy of an Android Application
10.1 Android Activities
10.2 Android Fragments
10.3 Android Intents
10.4 Broadcast Intents
10.5 Broadcast Receivers
10.6 Android Services
10.7 Content Providers
10.8 e Application Manifest
10.9 Application Resources
10.10 Application Context
10.11 Summary
11. An Overview of Android View Binding
11.1 Find View by Id
11.2 View Binding
11.3 Converting the AndroidSample project
11.4 Enabling View Binding
11.5 Using View Binding
11.6 Choosing an Option
11.7 View Binding in the Book Examples
11.8 Migrating a Project to View Binding
11.9 Summary
12. Understanding Android Application and Activity Lifecycles
12.1 Android Applications and Resource Management
12.2 Android Process States
12.2.1 Foreground Process
12.2.2 Visible Process
12.2.3 Service Process
12.2.4 Background Process
12.2.5 Empty Process
12.3 Inter-Process Dependencies
12.4 e Activity Lifecycle
12.5 e Activity Stack
12.6 Activity States
12.7 Con guration Changes
12.8 Handling State Change
12.9 Summary
13. Handling Android Activity State Changes
13.1 New vs. Old Lifecycle Techniques
13.2 e Activity and Fragment Classes
13.3 Dynamic State vs. Persistent State
13.4 e Android Lifecycle Methods
13.5 Lifetimes
13.6 Foldable Devices and Multi-Resume
13.7 Disabling Con guration Change Restarts
13.8 Lifecycle Method Limitations
13.9 Summary
14. Android Activity State Changes by Example
14.1 Creating the State Change Example Project
14.2 Designing the User Interface
14.3 Overriding the Activity Lifecycle Methods
14.4 Filtering the Logcat Panel
14.5 Running the Application
14.6 Experimenting with the Activity
14.7 Summary
15. Saving and Restoring the State of an Android Activity
15.1 Saving Dynamic State
15.2 Default Saving of User Interface State
15.3 e Bundle Class
15.4 Saving the State
15.5 Restoring the State
15.6 Testing the Application
15.7 Summary
16. Understanding Android Views, View Groups and Layouts
16.1 Designing for Di erent Android Devices
16.2 Views and View Groups
16.3 Android Layout Managers
16.4 e View Hierarchy
16.5 Creating User Interfaces
16.6 Summary
17. A Guide to the Android Studio Layout Editor Tool
17.1 Basic vs. Empty Activity Templates
17.2 e Android Studio Layout Editor
17.3 Design Mode
17.4 e Palette
17.5 Design Mode and Layout Views
17.6 Night Mode
17.7 Code Mode
17.8 Split Mode
17.9 Setting Attributes
17.10 Transforms
17.11 Tools Visibility Toggles
17.12 Converting Views
17.13 Displaying Sample Data
17.14 Creating a Custom Device De nition
17.15 Changing the Current Device
17.16 Layout Validation (Multi Preview)
17.17 Summary
18. A Guide to the Android ConstraintLayout
18.1 How ConstraintLayout Works
18.1.1 Constraints
18.1.2 Margins
18.1.3 Opposing Constraints
18.1.4 Constraint Bias
18.1.5 Chains
18.1.6 Chain Styles
18.2 Baseline Alignment
18.3 Con guring Widget Dimensions
18.4 Guideline Helper
18.5 Group Helper
18.6 Barrier Helper
18.7 Flow Helper
18.8 Ratios
18.9 ConstraintLayout Advantages
18.10 ConstraintLayout Availability
18.11 Summary
19. A Guide to Using ConstraintLayout in Android Studio
19.1 Design and Layout Views
19.2 Autoconnect Mode
19.3 Inference Mode
19.4 Manipulating Constraints Manually
19.5 Adding Constraints in the Inspector
19.6 Viewing Constraints in the Attributes Window
19.7 Deleting Constraints
19.8 Adjusting Constraint Bias
19.9 Understanding ConstraintLayout Margins
19.10 e Importance of Opposing Constraints and Bias
19.11 Con guring Widget Dimensions
19.12 Design Time Tools Positioning
19.13 Adding Guidelines
19.14 Adding Barriers
19.15 Adding a Group
19.16 Working with the Flow Helper
19.17 Widget Group Alignment and Distribution
19.18 Converting other Layouts to ConstraintLayout
19.19 Summary
20. Working with ConstraintLayout Chains and Ratios in Android
Studio
20.1 Creating a Chain
20.2 Changing the Chain Style
20.3 Spread Inside Chain Style
20.4 Packed Chain Style
20.5 Packed Chain Style with Bias
20.6 Weighted Chain
20.7 Working with Ratios
20.8 Summary
21. An Android Studio Layout Editor ConstraintLayout Tutorial
21.1 An Android Studio Layout Editor Tool Example
21.2 Creating a New Activity
21.3 Preparing the Layout Editor Environment
21.4 Adding the Widgets to the User Interface
21.5 Adding the Constraints
21.6 Testing the Layout
21.7 Using the Layout Inspector
21.8 Summary
22. Manual XML Layout Design in Android Studio
22.1 Manually Creating an XML Layout
22.2 Manual XML vs. Visual Layout Design
22.3 Summary
23. Managing Constraints using Constraint Sets
23.1 Java Code vs. XML Layout Files
23.2 Creating Views
23.3 View Attributes
23.4 Constraint Sets
23.4.1 Establishing Connections
23.4.2 Applying Constraints to a Layout
23.4.3 Parent Constraint Connections
23.4.4 Sizing Constraints
23.4.5 Constraint Bias
23.4.6 Alignment Constraints
23.4.7 Copying and Applying Constraint Sets
23.4.8 ConstraintLayout Chains
23.4.9 Guidelines
23.4.10 Removing Constraints
23.4.11 Scaling
23.4.12 Rotation
23.5 Summary
24. An Android ConstraintSet Tutorial
24.1 Creating the Example Project in Android Studio
24.2 Adding Views to an Activity
24.3 Setting View Attributes
24.4 Creating View IDs
24.5 Con guring the Constraint Set
24.6 Adding the EditText View
24.7 Converting Density Independent Pixels (dp) to Pixels (px)
24.8 Summary
25. A Guide to using Apply Changes in Android Studio
25.1 Introducing Apply Changes
25.2 Understanding Apply Changes Options
25.3 Using Apply Changes
25.4 Con guring Apply Changes Fallback Settings
25.5 An Apply Changes Tutorial
25.6 Using Apply Code Changes
25.7 Using Apply Changes and Restart Activity
25.8 Using Run App
25.9 Summary
26. An Overview and Example of Android Event Handling
26.1 Understanding Android Events
26.2 Using the android:onClick Resource
26.3 Event Listeners and Callback Methods
26.4 An Event Handling Example
26.5 Designing the User Interface
26.6 e Event Listener and Callback Method
26.7 Consuming Events
26.8 Summary
27. Android Touch and Multi-touch Event Handling
27.1 Intercepting Touch Events
27.2 e MotionEvent Object
27.3 Understanding Touch Actions
27.4 Handling Multiple Touches
27.5 An Example Multi-Touch Application
27.6 Designing the Activity User Interface
27.7 Implementing the Touch Event Listener
27.8 Running the Example Application
27.9 Summary
28. Detecting Common Gestures Using the Android Gesture Detector
Class
28.1 Implementing Common Gesture Detection
28.2 Creating an Example Gesture Detection Project
28.3 Implementing the Listener Class
28.4 Creating the GestureDetectorCompat Instance
28.5 Implementing the onTouchEvent() Method
28.6 Testing the Application
28.7 Summary
29. Implementing Custom Gesture and Pinch Recognition on Android
29.1 e Android Gesture Builder Application
29.2 e GestureOverlayView Class
29.3 Detecting Gestures
29.4 Identifying Speci c Gestures
29.5 Installing and Running the Gesture Builder Application
29.6 Creating a Gestures File
29.7 Creating the Example Project
29.8 Extracting the Gestures File from the SD Card
29.9 Adding the Gestures File to the Project
29.10 Designing the User Interface
29.11 Loading the Gestures File
29.12 Registering the Event Listener
29.13 Implementing the onGesturePerformed Method
29.14 Testing the Application
29.15 Con guring the GestureOverlayView
29.16 Intercepting Gestures
29.17 Detecting Pinch Gestures
29.18 A Pinch Gesture Example Project
29.19 Summary
30. An Introduction to Android Fragments
30.1 What is a Fragment?
30.2 Creating a Fragment
30.3 Adding a Fragment to an Activity using the Layout XML File
30.4 Adding and Managing Fragments in Code
30.5 Handling Fragment Events
30.6 Implementing Fragment Communication
30.7 Summary
31. Using Fragments in Android Studio - An Example
31.1 About the Example Fragment Application
31.2 Creating the Example Project
31.3 Creating the First Fragment Layout
31.4 Migrating a Fragment to View Binding
31.5 Adding the Second Fragment
31.6 Adding the Fragments to the Activity
31.7 Making the Toolbar Fragment Talk to the Activity
31.8 Making the Activity Talk to the Text Fragment
31.9 Testing the Application
31.10 Summary
32. Modern Android App Architecture with Jetpack
32.1 What is Android Jetpack?
32.2 e “Old” Architecture
32.3 Modern Android Architecture
32.4 e ViewModel Component
32.5 e LiveData Component
32.6 ViewModel Saved State
32.7 LiveData and Data Binding
32.8 Android Lifecycles
32.9 Repository Modules
32.10 Summary
33. An Android Jetpack ViewModel Tutorial
33.1 About the Project
33.2 Creating the ViewModel Example Project
33.3 Reviewing the Project
33.3.1 e Main Activity
33.3.2 e Content Fragment
33.3.3 e ViewModel
33.4 Designing the Fragment Layout
33.5 Implementing the View Model
33.6 Associating the Fragment with the View Model
33.7 Modifying the Fragment
33.8 Accessing the ViewModel Data
33.9 Testing the Project
33.10 Summary
34. An Android Jetpack LiveData Tutorial
34.1 LiveData - A Recap
34.2 Adding LiveData to the ViewModel
34.3 Implementing the Observer
34.4 Summary
35. An Overview of Android Jetpack Data Binding
35.1 An Overview of Data Binding
35.2 e Key Components of Data Binding
35.2.1 e Project Build Con guration
35.2.2 e Data Binding Layout File
35.2.3 e Layout File Data Element
35.2.4 e Binding Classes
35.2.5 Data Binding Variable Con guration
35.2.6 Binding Expressions (One-Way)
35.2.7 Binding Expressions (Two-Way)
35.2.8 Event and Listener Bindings
35.3 Summary
36. An Android Jetpack Data Binding Tutorial
36.1 Removing the Redundant Code
36.2 Enabling Data Binding
36.3 Adding the Layout Element
36.4 Adding the Data Element to Layout File
36.5 Working with the Binding Class
36.6 Assigning the ViewModel Instance to the Data Binding Variable
36.7 Adding Binding Expressions
36.8 Adding the Conversion Method
36.9 Adding a Listener Binding
36.10 Testing the App
36.11 Summary
37. An Android ViewModel Saved State Tutorial
37.1 Understanding ViewModel State Saving
37.2 Implementing ViewModel State Saving
37.3 Saving and Restoring State
37.4 Adding Saved State Support to the ViewModelDemo Project
37.5 Summary
38. Working with Android Lifecycle-Aware Components
38.1 Lifecycle Awareness
38.2 Lifecycle Owners
38.3 Lifecycle Observers
38.4 Lifecycle States and Events
38.5 Summary
39. An Android Jetpack Lifecycle Awareness Tutorial
39.1 Creating the Example Lifecycle Project
39.2 Creating a Lifecycle Observer
39.3 Adding the Observer
39.4 Testing the Observer
39.5 Creating a Lifecycle Owner
39.6 Testing the Custom Lifecycle Owner
39.7 Summary
40. An Overview of the Navigation Architecture Component
40.1 Understanding Navigation
40.2 Declaring a Navigation Host
40.3 e Navigation Graph
40.4 Accessing the Navigation Controller
40.5 Triggering a Navigation Action
40.6 Passing Arguments
40.7 Summary
41. An Android Jetpack Navigation Component Tutorial
41.1 Creating the NavigationDemo Project
41.2 Adding Navigation to the Build Con guration
41.3 Creating the Navigation Graph Resource File
41.4 Declaring a Navigation Host
41.5 Adding Navigation Destinations
41.6 Designing the Destination Fragment Layouts
41.7 Adding an Action to the Navigation Graph
41.8 Implement the OnFragmentInteractionListener
41.9 Adding View Binding Support to the Destination Fragments
41.10 Triggering the Action
41.11 Passing Data Using Safeargs
41.12 Summary
42. An Introduction to MotionLayout
42.1 An Overview of MotionLayout
42.2 MotionLayout
42.3 MotionScene
42.4 Con guring ConstraintSets
42.5 Custom Attributes
42.6 Triggering an Animation
42.7 Arc Motion
42.8 Keyframes
42.8.1 Attribute Keyframes
42.8.2 Position Keyframes
42.9 Time Linearity
42.10 KeyTrigger
42.11 Cycle and Time Cycle Keyframes
42.12 Starting an Animation from Code
42.13 Summary
43. An Android MotionLayout Editor Tutorial
43.1 Creating the MotionLayoutDemo Project
43.2 ConstraintLayout to MotionLayout Conversion
43.3 Con guring Start and End Constraints
43.4 Previewing the MotionLayout Animation
43.5 Adding an OnClick Gesture
43.6 Adding an Attribute Keyframe to the Transition
43.7 Adding a CustomAttribute to a Transition
43.8 Adding Position Keyframes
43.9 Summary
44. A MotionLayout KeyCycle Tutorial
44.1 An Overview of Cycle Keyframes
44.2 Using the Cycle Editor
44.3 Creating the KeyCycleDemo Project
44.4 Con guring the Start and End Constraints
44.5 Creating the Cycles
44.6 Previewing the Animation
44.7 Adding the KeyFrameSet to the MotionScene
44.8 Summary
45. Working with the Floating Action Button and Snackbar
45.1 e Material Design
45.2 e Design Library
45.3 e Floating Action Button (FAB)
45.4 e Snackbar
45.5 Creating the Example Project
45.6 Reviewing the Project
45.7 Removing Navigation Features
45.8 Changing the Floating Action Button
45.9 Adding an Action to the Snackbar
45.10 Summary
46. Creating a Tabbed Interface using the TabLayout Component
46.1 An Introduction to the ViewPager2
46.2 An Overview of the TabLayout Component
46.3 Creating the TabLayoutDemo Project
46.4 Creating the First Fragment
46.5 Duplicating the Fragments
46.6 Adding the TabLayout and ViewPager2
46.7 Creating the Pager Adapter
46.8 Performing the Initialization Tasks
46.9 Testing the Application
46.10 Customizing the TabLayout
46.11 Summary
47. Working with the RecyclerView and CardView Widgets
47.1 An Overview of the RecyclerView
47.2 An Overview of the CardView
47.3 Summary
48. An Android RecyclerView and CardView Tutorial
48.1 Creating the CardDemo Project
48.2 Modifying the Basic Activity Project
48.3 Designing the CardView Layout
48.4 Adding the RecyclerView
48.5 Adding the Image Files
48.6 Creating the RecyclerView Adapter
48.7 Initializing the RecyclerView Component
48.8 Testing the Application
48.9 Responding to Card Selections
48.10 Summary
49. A Layout Editor Sample Data Tutorial
49.1 Adding Sample Data to a Project
49.2 Using Custom Sample Data
49.3 Summary
50. Working with the AppBar and Collapsing Toolbar Layouts
50.1 e Anatomy of an AppBar
50.2 e Example Project
50.3 Coordinating the RecyclerView and Toolbar
50.4 Introducing the Collapsing Toolbar Layout
50.5 Changing the Title and Scrim Color
50.6 Summary
51. An Android Studio Primary/Detail Flow Tutorial
51.1 e Primary/Detail Flow
51.2 Creating a Primary/Detail Flow Activity
51.3 Modifying the Primary/Detail Flow Template
51.4 Changing the Content Model
51.5 Changing the Detail Pane
51.6 Modifying the WebsiteDetailFragment Class
51.7 Modifying the WebsiteListFragment Class
51.8 Adding Manifest Permissions
51.9 Running the Application
51.10 Summary
52. An Overview of Android Intents
52.1 An Overview of Intents
52.2 Explicit Intents
52.3 Returning Data from an Activity
52.4 Implicit Intents
52.5 Using Intent Filters
52.6 Checking Intent Availability
52.7 Summary
53. Android Explicit Intents – A Worked Example
53.1 Creating the Explicit Intent Example Application
53.2 Designing the User Interface Layout for MainActivity
53.3 Creating the Second Activity Class
53.4 Designing the User Interface Layout for SecondActivity
53.5 Reviewing the Application Manifest File
53.6 Creating the Intent
53.7 Extracting Intent Data
53.8 Launching SecondActivity as a Sub-Activity
53.9 Returning Data from a Sub-Activity
53.10 Testing the Application
53.11 Summary
54. Android Implicit Intents – A Worked Example
54.1 Creating the Android Studio Implicit Intent Example Project
54.2 Designing the User Interface
54.3 Creating the Implicit Intent
54.4 Adding a Second Matching Activity
54.5 Adding the Web View to the UI
54.6 Obtaining the Intent URL
54.7 Modifying the MyWebView Project Manifest File
54.8 Installing the MyWebView Package on a Device
54.9 Testing the Application
54.10 Summary
55. Android Broadcast Intents and Broadcast Receivers
55.1 An Overview of Broadcast Intents
55.2 An Overview of Broadcast Receivers
55.3 Obtaining Results from a Broadcast
55.4 Sticky Broadcast Intents
55.5 e Broadcast Intent Example
55.6 Creating the Example Application
55.7 Creating and Sending the Broadcast Intent
55.8 Creating the Broadcast Receiver
55.9 Registering the Broadcast Receiver
55.10 Testing the Broadcast Example
55.11 Listening for System Broadcasts
55.12 Summary
56. A Basic Overview of Java reads, Handlers and Executors
56.1 An Overview of reads
56.2 e Application Main read
56.3 read Handlers
56.4 A reading Example
56.5 Building the App
56.6 Creating a New read
56.7 Implementing a read Handler
56.8 Passing a Message to the Handler
56.9 Java Executor Concurrency
56.10 Working with Runnable Tasks
56.11 Shutting down an Executor Service
56.12 Working with Callable Tasks and Futures
56.13 Handling a Future Result
56.14 Scheduling Tasks
56.15 Summary
57. An Overview of Android Services
57.1 Started Services
57.2 Intent Service
57.3 Bound Service
57.4 e Anatomy of a Service
57.5 Controlling Destroyed Service Restart Options
57.6 Declaring a Service in the Manifest File
57.7 Starting a Service Running on System Startup
57.8 Summary
58. Implementing an Android Started Service – A Worked Example
58.1 Creating the Example Project
58.2 Designing the User Interface
58.3 Creating the Service Class
58.4 Adding the Service to the Manifest File
58.5 Starting the Service
58.6 Testing the IntentService Example
58.7 Using the Service Class
58.8 Creating the New Service
58.9 Launching the Service
58.10 Running the Application
58.11 Adding reading to the Service
58.12 Summary
59. Android Local Bound Services – A Worked Example
59.1 Understanding Bound Services
59.2 Bound Service Interaction Options
59.3 A Local Bound Service Example
59.4 Adding a Bound Service to the Project
59.5 Implementing the Binder
59.6 Binding the Client to the Service
59.7 Completing the Example
59.8 Testing the Application
59.9 Summary
60. Android Remote Bound Services – A Worked Example
60.1 Client to Remote Service Communication
60.2 Creating the Example Application
60.3 Designing the User Interface
60.4 Implementing the Remote Bound Service
60.5 Con guring a Remote Service in the Manifest File
60.6 Launching and Binding to the Remote Service
60.7 Sending a Message to the Remote Service
60.8 Summary
61. An Android Noti cations Tutorial
61.1 An Overview of Noti cations
61.2 Creating the NotifyDemo Project
61.3 Designing the User Interface
61.4 Creating the Second Activity
61.5 Creating a Noti cation Channel
61.6 Creating and Issuing a Noti cation
61.7 Launching an Activity from a Noti cation
61.8 Adding Actions to a Noti cation
61.9 Bundled Noti cations
61.10 Summary
62. An Android Direct Reply Noti cation Tutorial
62.1 Creating the DirectReply Project
62.2 Designing the User Interface
62.3 Creating the Noti cation Channel
62.4 Building the RemoteInput Object
62.5 Creating the PendingIntent
62.6 Creating the Reply Action
62.7 Receiving Direct Reply Input
62.8 Updating the Noti cation
62.9 Summary
63. Foldable Devices and Multi-Window Support
63.1 Foldables and Multi-Window Support
63.2 Using a Foldable Emulator
63.3 Entering Multi-Window Mode
63.4 Enabling and using Freeform Support
63.5 Checking for Freeform Support
63.6 Enabling Multi-Window Support in an App
63.7 Specifying Multi-Window Attributes
63.8 Detecting Multi-Window Mode in an Activity
63.9 Receiving Multi-Window Noti cations
63.10 Launching an Activity in Multi-Window Mode
63.11 Con guring Freeform Activity Size and Position
63.12 Summary
64. An Overview of Android SQLite Databases
64.1 Understanding Database Tables
64.2 Introducing Database Schema
64.3 Columns and Data Types
64.4 Database Rows
64.5 Introducing Primary Keys
64.6 What is SQLite?
64.7 Structured Query Language (SQL)
64.8 Trying SQLite on an Android Virtual Device (AVD)
64.9 e Android Room Persistence Library
64.10 Summary
65. e Android Room Persistence Library
65.1 Revisiting Modern App Architecture
65.2 Key Elements of Room Database Persistence
65.2.1 Repository
65.2.2 Room Database
65.2.3 Data Access Object (DAO)
65.2.4 Entities
65.2.5 SQLite Database
65.3 Understanding Entities
65.4 Data Access Objects
65.5 e Room Database
65.6 e Repository
65.7 In-Memory Databases
65.8 Database Inspector
65.9 Summary
66. An Android TableLayout and TableRow Tutorial
66.1 e TableLayout and TableRow Layout Views
66.2 Creating the Room Database Project
66.3 Converting to a LinearLayout
66.4 Adding the TableLayout to the User Interface
66.5 Con guring the TableRows
66.6 Adding the Button Bar to the Layout
66.7 Adding the RecyclerView
66.8 Adjusting the Layout Margins
66.9 Summary
67. An Android Room Database and Repository Tutorial
67.1 About the RoomDemo Project
67.2 Modifying the Build Con guration
67.3 Building the Entity
67.4 Creating the Data Access Object
67.5 Adding the Room Database
67.6 Adding the Repository
67.7 Modifying the ViewModel
67.8 Creating the Product Item Layout
67.9 Adding the RecyclerView Adapter
67.10 Preparing the Main Fragment
67.11 Adding the Button Listeners
67.12 Adding LiveData Observers
67.13 Initializing the RecyclerView
67.14 Testing the RoomDemo App
67.15 Using the Database Inspector
67.16 Summary
68. Accessing Cloud Storage using the Android Storage Access
Framework
68.1 e Storage Access Framework
68.2 Working with the Storage Access Framework
68.3 Filtering Picker File Listings
68.4 Handling Intent Results
68.5 Reading the Content of a File
68.6 Writing Content to a File
68.7 Deleting a File
68.8 Gaining Persistent Access to a File
68.9 Summary
69. An Android Storage Access Framework Example
69.1 About the Storage Access Framework Example
69.2 Creating the Storage Access Framework Example
69.3 Designing the User Interface
69.4 Adding the Activity Launchers
69.5 Creating a New Storage File
69.6 Saving to a Storage File
69.7 Opening and Reading a Storage File
69.8 Testing the Storage Access Application
69.9 Summary
70. Video Playback on Android using the VideoView and
MediaController Classes
70.1 Introducing the Android VideoView Class
70.2 Introducing the Android MediaController Class
70.3 Creating the Video Playback Example
70.4 Designing the VideoPlayer Layout
70.5 Downloading the Video File
70.6 Con guring the VideoView
70.7 Adding the MediaController to the Video View
70.8 Setting up the onPreparedListener
70.9 Summary
71. Android Picture-in-Picture Mode
71.1 Picture-in-Picture Features
71.2 Enabling Picture-in-Picture Mode
71.3 Con guring Picture-in-Picture Parameters
71.4 Entering Picture-in-Picture Mode
71.5 Detecting Picture-in-Picture Mode Changes
71.6 Adding Picture-in-Picture Actions
71.7 Summary
72. An Android Picture-in-Picture Tutorial
72.1 Adding Picture-in-Picture Support to the Manifest
72.2 Adding a Picture-in-Picture Button
72.3 Entering Picture-in-Picture Mode
72.4 Detecting Picture-in-Picture Mode Changes
72.5 Adding a Broadcast Receiver
72.6 Adding the PiP Action
72.7 Testing the Picture-in-Picture Action
72.8 Summary
73. Making Runtime Permission Requests in Android
73.1 Understanding Normal and Dangerous Permissions
73.2 Creating the Permissions Example Project
73.3 Checking for a Permission
73.4 Requesting Permission at Runtime
73.5 Providing a Rationale for the Permission Request
73.6 Testing the Permissions App
73.7 Summary
74. Android Audio Recording and Playback using MediaPlayer and
MediaRecorder
74.1 Playing Audio
74.2 Recording Audio and Video using the MediaRecorder Class
74.3 About the Example Project
74.4 Creating the AudioApp Project
74.5 Designing the User Interface
74.6 Checking for Microphone Availability
74.7 Initializing the Activity
74.8 Implementing the recordAudio() Method
74.9 Implementing the stopAudio() Method
74.10 Implementing the playAudio() method
74.11 Con guring and Requesting Permissions
74.12 Testing the Application
74.13 Summary
75. Working with the Google Maps Android API in Android Studio
75.1 e Elements of the Google Maps Android API
75.2 Creating the Google Maps Project
75.3 Obtaining Your Developer Signature
75.4 Adding the Apache HTTP Legacy Library Requirement
75.5 Testing the Application
75.6 Understanding Geocoding and Reverse Geocoding
75.7 Adding a Map to an Application
75.8 Requesting Current Location Permission
75.9 Displaying the User’s Current Location
75.10 Changing the Map Type
75.11 Displaying Map Controls to the User
75.12 Handling Map Gesture Interaction
75.12.1 Map Zooming Gestures
75.12.2 Map Scrolling/Panning Gestures
75.12.3 Map Tilt Gestures
75.12.4 Map Rotation Gestures
75.13 Creating Map Markers
75.14 Controlling the Map Camera
75.15 Summary
76. Printing with the Android Printing Framework
76.1 e Android Printing Architecture
76.2 e Print Service Plugins
76.3 Google Cloud Print
76.4 Printing to Google Drive
76.5 Save as PDF
76.6 Printing from Android Devices
76.7 Options for Building Print Support into Android Apps
76.7.1 Image Printing
76.7.2 Creating and Printing HTML Content
76.7.3 Printing a Web Page
76.7.4 Printing a Custom Document
76.8 Summary
77. An Android HTML and Web Content Printing Example
77.1 Creating the HTML Printing Example Application
77.2 Printing Dynamic HTML Content
77.3 Creating the Web Page Printing Example
77.4 Removing the Floating Action Button
77.5 Removing Navigation Features
77.6 Designing the User Interface Layout
77.7 Accessing the WebView from the Main Activity
77.8 Loading the Web Page into the WebView
77.9 Adding the Print Menu Option
77.10 Summary
78. A Guide to Android Custom Document Printing
78.1 An Overview of Android Custom Document Printing
78.1.1 Custom Print Adapters
78.2 Preparing the Custom Document Printing Project
78.3 Creating the Custom Print Adapter
78.4 Implementing the onLayout() Callback Method
78.5 Implementing the onWrite() Callback Method
78.6 Checking a Page is in Range
78.7 Drawing the Content on the Page Canvas
78.8 Starting the Print Job
78.9 Testing the Application
78.10 Summary
79. An Introduction to Android App Links
79.1 An Overview of Android App Links
79.2 App Link Intent Filters
79.3 Handling App Link Intents
79.4 Associating the App with a Website
79.5 Summary
80. An Android Studio App Links Tutorial
80.1 About the Example App
80.2 e Database Schema
80.3 Loading and Running the Project
80.4 Adding the URL Mapping
80.5 Adding the Intent Filter
80.6 Adding Intent Handling Code
80.7 Testing the App Link
80.8 Associating an App Link with a Web Site
80.9 Summary
81. An Android Biometric Authentication Tutorial
81.1 An Overview of Biometric Authentication
81.2 Creating the Biometric Authentication Project
81.3 Con guring Device Fingerprint Authentication
81.4 Adding the Biometric Permission to the Manifest File
81.5 Designing the User Interface
81.6 Adding a Toast Convenience Method
81.7 Checking the Security Settings
81.8 Con guring the Authentication Callbacks
81.9 Adding the CancellationSignal
81.10 Starting the Biometric Prompt
81.11 Testing the Project
81.12 Summary
82. Creating, Testing and Uploading an Android App Bundle
82.1 e Release Preparation Process
82.2 Android App Bundles
82.3 Register for a Google Play Developer Console Account
82.4 Con guring the App in the Console
82.5 Enabling Google Play App Signing
82.6 Creating a Keystore File
82.7 Creating the Android App Bundle
82.8 Generating Test APK Files
82.9 Uploading the App Bundle to the Google Play Developer Console
82.10 Exploring the App Bundle
82.11 Managing Testers
82.12 Rolling the App Out for Testing
82.13 Uploading New App Bundle Revisions
82.14 Analyzing the App Bundle File
82.15 Summary
83. An Overview of Android Dynamic Feature Modules
83.1 An Overview of Dynamic Feature Modules
83.2 Dynamic Feature Module Architecture
83.3 Creating a Dynamic Feature Module
83.4 Converting an Existing Module for Dynamic Delivery
83.5 Working with Dynamic Feature Modules
83.6 Handling Large Dynamic Feature Modules
83.7 Summary
84. An Android Studio Dynamic Feature Tutorial
84.1 Creating the DynamicFeature Project
84.2 Adding Dynamic Feature Support to the Project
84.3 Designing the Base Activity User Interface
84.4 Adding the Dynamic Feature Module
84.5 Reviewing the Dynamic Feature Module
84.6 Adding the Dynamic Feature Activity
84.7 Implementing the launchIntent() Method
84.8 Uploading the App Bundle for Testing
84.9 Implementing the installFeature() Method
84.10 Adding the Update Listener
84.11 Using Deferred Installation
84.12 Removing a Dynamic Module
84.13 Summary
85. An Overview of Gradle in Android Studio
85.1 An Overview of Gradle
85.2 Gradle and Android Studio
85.2.1 Sensible Defaults
85.2.2 Dependencies
85.2.3 Build Variants
85.2.4 Manifest Entries
85.2.5 APK Signing
85.2.6 ProGuard Support
85.3 e Top-level Gradle Build File
85.4 Module Level Gradle Build Files
85.5 Con guring Signing Settings in the Build File
85.6 Running Gradle Tasks from the Command-line
85.7 Summary
Index
1. Introduction
Fully updated for Android Studio Arctic Fox, the goal of this book is to
teach the skills necessary to develop Android based applications using the
Java programming language.
Beginning with the basics, this book provides an outline of the steps
necessary to set up an Android development and testing environment. An
overview of Android Studio is included covering areas such as tool windows,
the code editor and the Layout Editor tool. An introduction to the
architecture of Android is followed by an in-depth look at the design of
Android applications and user interfaces using the Android Studio
environment.
Chapters are also included covering the Android Architecture Components
including view models, lifecycle management, Room database access, the
Database Inspector, app navigation, live data and data binding.
More advanced topics such as intents are also covered, as are touch screen
handling, gesture recognition, and the recording and playback of audio. is
edition of the book also covers printing, transitions, cloud-based le storage
and foldable device support.
e concepts of material design are also covered in detail, including the use
of oating action buttons, Snackbars, tabbed interfaces, card views,
navigation drawers and collapsing toolbars.
Other key features of Android Studio Arctic Fox and Android are also
covered in detail including the Layout Editor, the ConstraintLayout and
ConstraintSet classes, MotionLayout Editor, view binding, constraint chains,
barriers and direct reply noti cations.
Chapters also cover advanced features of Android Studio such as App Links,
Dynamic Delivery, Gradle build con guration, and submitting apps to the
Google Play Developer Console.
Assuming you already have some Java programming experience, are ready
to download Android Studio and the Android SDK, have access to a
Windows, Mac or Linux system and ideas for some apps to develop, you are
ready to get started.
1.1 Downloading the Code Samples
e source code and Android Studio project les for the examples contained
in this book are available for download at:
https://www.ebookfrenzy.com/retail/arcticfoxjava/index.php
e steps to load a project from the code samples into Android Studio are as
follows:
1. From the Welcome to Android Studio dialog, click on the Open button
option.
2. In the project selection dialog, navigate to and select the folder containing
the project to be imported and click on OK.
1.2 Feedback
We want you to be satis ed with your purchase of this book. If you nd any
errors in the book, or have any comments, questions or concerns please
contact us at [email protected].
1.3 Errata
While we make every e ort to ensure the accuracy of the content of this
book, it is inevitable that a book covering a subject area of this size and
complexity may include some errors and oversights. Any known issues with
the book will be outlined, together with solutions, at the following URL:
https://www.ebookfrenzy.com/errata/arcticfoxjava.html
In the event that you nd an error not listed in the errata, please let us know
by emailing our technical support team at [email protected]. ey
are there to help you and will work to resolve any problems you may
encounter.
2. Setting up an Android Studio Development
Environment
Before any work can begin on the development of an Android application,
the rst step is to con gure a computer system to act as the development
platform. is involves a number of steps consisting of installing the
Android Studio Integrated Development Environment (IDE) which also
includes the Android So ware Development Kit (SDK) and OpenJDK Java
development environment.
is chapter will cover the steps necessary to install the requisite
components for Android application development on Windows, macOS and
Linux based systems.
2.1 System Requirements
Android application development may be performed on any of the following
system types:
•Windows 8/10 64-bit
•macOS 10.14 or later, Intel Core, AMD, or Apple silicon
•Chrome OS device with Intel i5 or higher
•Linux systems with version 2.31 or later of GNU C Library (glibc)
•Minimum of 8GB of RAM
•Approximately 8GB of available disk space
•1280 x 800 minimum screen resolution
2.2 Downloading the Android Studio Package
Most of the work involved in developing applications for Android will be
performed using the Android Studio environment. e content and
examples in this book were created based on Android Studio Arctic Fox
2020.3.1 using the Android 11.0 (R) API 30 SDK which, at the time of
writing, are the current versions.
Android Studio is, however, subject to frequent updates so a newer version
may have been released since this book was published.
e latest release of Android Studio may be downloaded from the primary
download page which can be found at the following URL:
https://developer.android.com/studio/index.html
If this page provides instructions for downloading a newer version of
Android Studio it is important to note that there may be some minor
di erences between this book and the so ware. A web search for “Android
Studio Arctic Fox” should provide the option to download the older version
in the event that these di erences become a problem. Alternatively, visit the
following web page to nd Android Studio Arctic Fox in the archives:
https://developer.android.com/studio/archive
2.3 Installing Android Studio
Once downloaded, the exact steps to install Android Studio di er
depending on the operating system on which the installation is being
performed.
2.3.1 Installation on Windows
Locate the downloaded Android Studio installation executable le (named
android-studio-<version>-windows.exe) in a Windows Explorer window and
double-click on it to start the installation process, clicking the Yes button in
the User Account Control dialog if it appears.
Once the Android Studio setup wizard appears, work through the various
screens to con gure the installation to meet your requirements in terms of
the le system location into which Android Studio should be installed and
whether or not it should be made available to other users of the system.
When prompted to select the components to install, make sure that the
Android Studio and Android Virtual Device options are all selected.
Although there are no strict rules on where Android Studio should be
installed on the system, the remainder of this book will assume that the
installation was performed into C:\Program Files\Android\Android Studio
and that the Android SDK packages have been installed into the user’s
AppData\Local\Android\sdk sub-folder. Once the options have been
con gured, click on the Install button to begin the installation process.
On versions of Windows with a Start menu, the newly installed Android
Studio can be launched from the entry added to that menu during the
installation. e executable may be pinned to the task bar for easy access by
navigating to the Android Studio\bin directory, right-clicking on the
executable and selecting the Pin to Taskbar menu option.
2.3.2 Installation on macOS
Android Studio for macOS is downloaded in the form of a disk image
(.dmg) le. Once the android-studio-<version>-mac.dmg le has been
downloaded, locate it in a Finder window and double-click on it to open it
as shown in Figure 2-1:

Figure 2-1
To install the package, simply drag the Android Studio icon and drop it onto
the Applications folder. e Android Studio package will then be installed
into the Applications folder of the system, a process which will typically take
a few seconds to complete.
To launch Android Studio, locate the executable in the Applications folder
using a Finder window and double-click on it.
For future easier access to the tool, drag the Android Studio icon from the
Finder window and drop it onto the dock.
2.3.3 Installation on Linux
Having downloaded the Linux Android Studio package, open a terminal
window, change directory to the location where Android Studio is to be
installed and execute the following command:
unzip /<path to package>/android-studio-ide-<version>-
linux.zip
Note that the Android Studio bundle will be installed into a sub-directory
named android-studio. Assuming, therefore, that the above command was
executed in /home/demo, the so ware packages will be unpacked into
/home/demo/android-studio.
To launch Android Studio, open a terminal window, change directory to the
android-studio/bin sub-directory and execute the following command:
./studio.sh
When running on a 64-bit Linux system, it will be necessary to install some
32-bit support libraries before Android Studio will run. On Ubuntu these
libraries can be installed using the following command:
sudo apt-get install libc6:i386 libncurses5:i386
libstdc++6:i386 lib32z1 libbz2-1.0:i386
On Red Hat and Fedora based 64-bit systems, use the following command:
sudo yum install zlib.i686 ncurses-libs.i686 bzip2-
libs.i686
2.4 e Android Studio Setup Wizard
If you are installing Android Studio for the rst time the initial dialog that
appears once the setup process starts may resemble that shown in Figure 2-2
below:

Figure 2-2
If this dialog appears, click the Next button to display the SDK Components
Setup dialog (Figure 2-3). Within this dialog, make sure that the Android
SDK option is selected along with the latest API package before clicking on
the Next button:
Figure 2-3
A er clicking Next, Android Studio will download and install the Android
SDK and tools.
If you have previously installed an earlier version of Android Studio, the rst
time that this new version is launched, a dialog may appear providing the
option to import settings from a previous Android Studio version. If you
have settings from a previous version and would like to import them into
the latest installation, select the appropriate option and location.
Alternatively, indicate that you do not need to import any previous settings
and click on the OK button to proceed.
A er these initial setup steps have been taken, click the Finish button to
display the Welcome to Android Studio screen:

Figure 2-4
2.5 Installing Additional Android SDK Packages
e steps performed so far have installed the Android Studio IDE and the
current set of default Android SDK packages. Before proceeding, it is worth
taking some time to verify which packages are installed and to install any
missing or updated packages.
is task can be performed by clicking on the More Actions link in the
within the welcome dialog and selecting the SDK Manager option from the
drop down menu. Once invoked, the Android SDK screen of the Preferences
dialog will appear as shown in Figure 2-5:

Figure 2-5
Immediately a er installing Android Studio for the rst time it is likely that
only the latest released version of the Android SDK has been installed. To
install older versions of the Android SDK simply select the checkboxes
corresponding to the versions and click on the Apply button.
Most of the examples in this book will support older versions of Android as
far back as far as Android 8.0 (Oreo). is is to ensure that the apps run on a
wide range of Android devices. Within the list of SDK versions, enable the
checkbox next to Android 8.0 (Oreo) and click on the Apply button. In the
resulting con rmation dialog click on the OK button to install the SDK.
Subsequent dialogs will seek acceptance of licenses and terms before
performing the installation. Click Finish once the installation is complete.
It is also possible that updates will be listed as being available for the latest
SDK. To access detailed information about the packages that are available
for update, enable the Show Package Details option located in the lower
right-hand corner of the screen. is will display information similar to that
shown in Figure 2-6:

Figure 2-6
e above gure highlights the availability of an update. To install the
updates, enable the checkbox to the le of the item name and click on the
Apply button.
In addition to the Android SDK packages, a number of tools are also
installed for building Android applications. To view the currently installed
packages and check for updates, remain within the SDK settings screen and
select the SDK Tools tab as shown in Figure 2-7:

Figure 2-7
Within the Android SDK Tools screen, make sure that the following
packages are listed as Installed in the Status column:
•Android SDK Build-tools
•Android Emulator
•Android SDK Platform-tools
•Google Play Services
•Intel x86 Emulator Accelerator (HAXM installer)
•Google USB Driver (Windows only)
•Layout Inspector image server
Note the Intel x86 Emulator Accelerator (HAXM installer) cannot be
installed on Apple silicon-based Macs.
In the event that any of the above packages are listed as Not Installed or
requiring an update, simply select the checkboxes next to those packages
and click on the Apply button to initiate the installation process. If the
HAXM emulator settings dialog appears, select the recommended memory
allocation:

Figure 2-8
Once the installation is complete, review the package list and make sure that
the selected packages are now listed as Installed in the Status column. If any
are listed as Not installed, make sure they are selected and click on the Apply
button again.
2.6 Making the Android SDK Tools Command-line
Accessible
Most of the time, the underlying tools of the Android SDK will be accessed
from within the Android Studio environment. at being said, however,
there will also be instances where it will be useful to be able to invoke those
tools from a command prompt or terminal window. In order for the
operating system on which you are developing to be able to nd these tools,
it will be necessary to add them to the system’s PATH environment variable.
Regardless of operating system, the PATH variable needs to be con gured to
include the following paths (where <path_to_android_sdk_installation>
represents the le system location into which the Android SDK was
installed):
<path_to_android_sdk_installation>/sdk/tools
<path_to_android_sdk_installation>/sdk/tools/bin
<path_to_android_sdk_installation>/sdk/platform-tools
e location of the SDK on your system can be identi ed by launching the
SDK Manager and referring to the Android SDK Location: eld located at the
top of the settings panel as highlighted in Figure 2-9:

Figure 2-9
Once the location of the SDK has been identi ed, the steps to add this to the
PATH variable are operating system dependent:
2.6.1 Windows 8.1
1. On the start screen, move the mouse to the bottom right-hand corner of
the screen and select Search from the resulting menu. In the search box,
enter Control Panel. When the Control Panel icon appears in the results
area, click on it to launch the tool on the desktop.
2. Within the Control Panel, use the Category menu to change the display to
Large Icons. From the list of icons select the one labeled System.
3. In the Environment Variables dialog, locate the Path variable in the
System variables list, select it and click on the Edit… button. Using the
New button in the edit dialog, add three new entries to the path. For
example, assuming the Android SDK was installed into
C:\Users\demo\AppData\Local\Android\Sdk, the following entries would
need to be added:
C:\Users\demo\AppData\Local\Android\Sdk\platform-tools
C:\Users\demo\AppData\Local\Android\Sdk\tools
C:\Users\demo\AppData\Local\Android\Sdk\tools\bin
4. Click on OK in each dialog box and close the system properties control
panel.
Open the command prompt window (move the mouse to the bottom right-
hand corner of the screen, select the Search option and enter cmd into the
search box). Select Command Prompt from the search results.
Within the Command Prompt window, enter:
echo %Path%
e returned path variable value should include the paths to the Android
SDK platform tools folders. Verify that the platform-tools value is correct by
attempting to run the adb tool as follows:
adb
e tool should output a list of command line options when executed.
Similarly, check the tools path setting by attempting to run the AVD
Manager command line tool (don’t worry if the avdmanager tool reports a
problem with Java - this will be addressed later):
avdmanager
In the event that a message similar to the following message appears for one
or both of the commands, it is most likely that an incorrect path was
appended to the Path environment variable:
'adb' is not recognized as an internal or external
command,
operable program or batch file.
2.6.2 Windows 10
Right-click on the Start menu, select Settings from the resulting menu and
enter “Edit the system environment variables” into the Find a setting text
eld. In the System Properties dialog, click the Environment Variables...
button. Follow the steps outlined for Windows 8.1 starting from step 3.
2.6.3 Linux
On Linux, this con guration can typically be achieved by adding a
command to the .bashrc le in your home directory (speci cs may di er
depending on the particular Linux distribution in use). Assuming that the
Android SDK bundle package was installed into /home/demo/Android/sdk,
the export line in the .bashrc le would read as follows:
export PATH=/home/demo/Android/sdk/platform-
tools:/home/demo/Android/sdk/tools:/home/demo/Android/sdk/
tools/bin:/home/demo/android-studio/bin:$PATH
Note also that the above command adds the android-studio/bin directory to
the PATH variable. is will enable the studio.sh script to be executed
regardless of the current directory within a terminal window.
2.6.4 macOS
A number of techniques may be employed to modify the $PATH
environment variable on macOS. Arguably the cleanest method is to add a
new le in the /etc/paths.d directory containing the paths to be added to
$PATH. Assuming an Android SDK installation location of
/Users/demo/Library/Android/sdk, the path may be con gured by creating a
new le named android-sdk in the /etc/paths.d directory containing the
following lines:
/Users/demo/Library/Android/sdk/tools
/Users/demo/Library/Android/sdk/tools/bin
/Users/demo/Library/Android/sdk/platform-tools
Note that since this is a system directory it will be necessary to use the sudo
command when creating the le. For example:
sudo vi /etc/paths.d/android-sdk
2.7 Android Studio Memory Management
Android Studio is a large and complex so ware application that consists of
many background processes. Although Android Studio has been criticized
in the past for providing less than optimal performance, Google has made
signi cant performance improvements in recent releases and continues to
do so with each new version. Part of these improvements include allowing
the user to con gure the amount of memory used by both the Android
Studio IDE and the background processes used to build and run apps. is
allows the so ware to take advantage of systems with larger amounts of
RAM.
If you are running Android Studio on a system with su cient unused RAM
to increase these values (this feature is only available on 64-bit systems with
5GB or more of RAM) and nd that Android Studio performance appears to
be degraded it may be worth experimenting with these memory settings.
Android Studio may also notify you that performance can be increased via a
dialog similar to the one shown below:
Figure 2-10
To view and modify the current memory con guration, select the File ->
Settings... (Android Studio -> Preferences... on macOS) menu option and, in
the resulting dialog, select the Memory Settings option listed under System
Settings in the le -hand navigation panel as illustrated in Figure 2-11 below.
When changing the memory allocation, be sure not to allocate more
memory than necessary or than your system can spare without slowing
down other processes.

Figure 2-11
2.8 Updating Android Studio and the SDK
From time to time new versions of Android Studio and the Android SDK
are released. New versions of the SDK are installed using the Android SDK
Manager. Android Studio will typically notify you when an update is ready
to be installed.
To manually check for Android Studio updates, use the Help -> Check for
Updates... menu option from the Android Studio main window (Android
Studio -> Check for Updates... on macOS).
2.9 Summary
Prior to beginning the development of Android based applications, the rst
step is to set up a suitable development environment. is consists of the
Android SDKs and Android Studio IDE (which also includes the OpenJDK
development environment). In this chapter, we have covered the steps
necessary to install these packages on Windows, macOS and Linux.
3. Creating an Example Android App in Android
Studio
e preceding chapters of this book have covered the steps necessary to
con gure an environment suitable for the development of Android
applications using the Android Studio IDE. Before moving on to slightly
more advanced topics, now is a good time to validate that all of the required
development packages are installed and functioning correctly. e best way
to achieve this goal is to create an Android application and compile and run
it. is chapter will cover the creation of an Android application project
using Android Studio. Once the project has been created, a later chapter will
explore the use of the Android emulator environment to perform a test run
of the application.
3.1 About the Project
e project created in this chapter takes the form of a rudimentary currency
conversion calculator (so simple, in fact, that it only converts from dollars to
euros and does so using an estimated conversion rate). e project will also
make use of one of the most basic of Android Studio project templates. is
simplicity allows us to introduce some of the key aspects of Android app
development without overwhelming the beginner by trying to introduce too
many concepts, such as the recommended app architecture and Android
architecture components, at once. When following the tutorial in this
chapter, rest assured that all of the techniques and code used in this initial
example project will be covered in much greater detail in later chapters.
3.2 Creating a New Android Project
e rst step in the application development process is to create a new
project within the Android Studio environment. Begin, therefore, by
launching Android Studio so that the “Welcome to Android Studio” screen
appears as illustrated in Figure 3-1:
Figure 3-1
Once this window appears, Android Studio is ready for a new project to be
created. To create the new project, simply click on the New Project option to
display the rst screen of the New Project wizard.
3.3 Creating an Activity
e rst step is to de ne the type of initial activity that is to be created for
the application. Options are available to create projects for Phone and
Tablet, Wear OS, TV, Android Audio or Android ings. A range of
di erent activity types is available when developing Android applications,
many of which will be covered extensively in later chapters. For the purposes
of this example, however, simply select the Phone and Tablet option from the
Templates panel followed by the option to create an Empty Activity. e
Empty Activity option creates a template user interface consisting of a single
TextView object.

Figure 3-2
With the Empty Activity option selected, click Next to continue with the
project con guration.
3.4 De ning the Project and SDK Settings
In the project con guration window (Figure 3-3), set the Name eld to
AndroidSample. e application name is the name by which the application
will be referenced and identi ed within Android Studio and is also the name
that would be used if the completed application were to go on sale in the
Google Play store.
e Package name is used to uniquely identify the application within the
Android application ecosystem. Although this can be set to any string that
uniquely identi es your app, it is traditionally based on the reversed URL of
your domain name followed by the name of the application. For example, if
your domain is www.mycompany.com, and the application has been named
AndroidSample, then the package name might be speci ed as follows:
com.mycompany.androidsample
If you do not have a domain name you can enter any other string into the
Company Domain eld, or you may use example.com for the purposes of
testing, though this will need to be changed before an application can be
published:
com.example.androidsample
e Save location setting will default to a location in the folder named
AndroidStudioProjects located in your home directory and may be changed
by clicking on the folder icon to the right of the text eld containing the
current path setting.
Set the minimum SDK setting to API 26: Android 8.0 (Oreo). is is the
minimum SDK that will be used in most of the projects created in this book
unless a necessary feature is only available in a more recent version. e
objective here is to build an app using the latest Android SDK, while also
retaining compatibility with devices running older versions of Android (in
this case as far back as Android 8.0). e text beneath the Minimum SDK
setting will outline the percentage of Android devices currently in use on
which the app will run. Click on the Help me choose button (highlighted in
Figure 3-3) to see a full breakdown of the various Android versions still in
use:
Figure 3-3
Finally, change the Language menu to Java and click on Finish to initiate the
project creation process.
3.5 Modifying the Example Application
At this point, Android Studio has created a minimal example application
project and opened the main window.

Figure 3-4
e newly created project and references to associated les are listed in the
Project tool window located on the le -hand side of the main project
window. e Project tool window has a number of modes in which
information can be displayed. By default, this panel should be in Android
mode. is setting is controlled by the menu at the top of the panel as
highlighted in Figure 3-5. If the panel is not currently in Android mode, use
the menu to switch mode:

Figure 3-5
3.6 Modifying the User Interface
e user interface design for our activity is stored in a le named
activity_main.xml which, in turn, is located under app -> res -> layout in the
project le hierarchy. Once located in the Project tool window, double-click
on the le to load it into the user interface Layout Editor tool which will
appear in the center panel of the Android Studio main window:

Figure 3-6
In the toolbar across the top of the Layout Editor window is a menu
(currently set to Pixel in the above gure) which is re ected in the visual
representation of the device within the Layout Editor panel. A wide range of
other device options are available for selection by clicking on this menu.
To change the orientation of the device representation between landscape
and portrait simply use the drop down menu immediately to the le of the
device selection menu showing the icon.
As can be seen in the device screen, the content layout already includes a
label that displays a “Hello World!” message. Running down the le -hand
side of the panel is a palette containing di erent categories of user interface
components that may be used to construct a user interface, such as buttons,
labels and text elds. It should be noted, however, that not all user interface
components are obviously visible to the user. One such category consists of
layouts. Android supports a variety of layouts that provide di erent levels of
control over how visual user interface components are positioned and
managed on the screen. ough it is di cult to tell from looking at the
visual representation of the user interface, the current design has been
created using a ConstraintLayout. is can be con rmed by reviewing the
information in the Component Tree panel which, by default, is located in the
lower le -hand corner of the Layout Editor panel and is shown in Figure 3-
7:

Figure 3-7
As we can see from the component tree hierarchy, the user interface layout
consists of a ConstraintLayout parent and a TextView child object.
Before proceeding, also check that the Layout Editor’s Autoconnect mode is
enabled. is means that as components are added to the layout, the Layout
Editor will automatically add constraints to make sure the components are
correctly positioned for di erent screen sizes and device orientations (a
topic that will be covered in much greater detail in future chapters). e
Autoconnect button appears in the Layout Editor toolbar and is represented
by a magnet icon. When disabled the magnet appears with a diagonal line
through it (Figure 3-8). If necessary, re-enable Autoconnect mode by
clicking on this button.
Another Random Scribd Document
with Unrelated Content
"I knew it," said Ravenel. "Now then, I am a country doctor. I can
take this young man to a plantation, and give him pure air."
"That's what you want," observed Jackson, turning to Colburne.
"Your arm don't need ice now. Water will do. Better go, I think. I'll
see that you have a month's leave of absence. Come, you can go to
Taylorsville, and still not miss a chance for fighting. Tried to send
him north," he added, addressing Ravenel. "But he's foolish about it.
Wants to see Port Hudson out—what you call a knight-errant."
Colburne was in a tremble, body and soul, at the thought of meeting
Mrs. Carter; he had never been so profoundly shaken by even the
actuality of encountering Miss Ravenel. Most of us have been in love
enough to understand all about it without explanation, and to feel no
wonder at him because, after reeling mentally this way and that, he
finally said, "I will go." Now and then there is a woman who cannot
bear to look upon the man whom she has loved and lost, and who
will turn quick corners and run down side streets to escape him,
haunting him spiritually perhaps, but bodily keeping afar from him all
her life. But stronger natures, who can endure the trial, frequently
go to meet it, and seem to find some dolorous comfort in it. As
regards Colburne, it may be that he would not have gone to
Taylorsville had he not been weak and feverish, and felt a craving for
that petting kindness which seems to be a necessity of invalids.
I doubt whether the life in Ravenel's house contributed much to
advance his convalescence. His emotions were played upon too
constantly and powerfully for the highest good of the temporarily
shattered instrument. He had supposed that he would undergo one
great shock on meeting Mrs. Carter, and that then his trouble would
be over. The first thrill was not so potent as he expected; but it was
succeeded by a constant unrest, like the burning of a slow fever; he
was uneasy all day and slept badly at night. In the house he could
not talk freely and gaily, because of Lillie's presence; and out of it he
could not feel with calmness, because he was perpetually thinking of
her. After all, it may have been the splinters of bone in the arm,
quite as much as the arrow in the heart, which worried him. Of Mrs.
Carter I must admit that she was not merciful; she made the doubly-
wounded Captain talk a great deal of his Colonel. He might recite
Carter's martial deeds and qualities as lengthily as he pleased, and
recommence da capo to recite them over again, not only without
fatiguing her, but without exciting in her mind a thought that he was
doing any thing remarkable. She was very much pleased, but she
was not a bit grateful. Why should she be! It was perfectly natural to
her mind that people should admire the Colonel, and talk much of
his glory. Colburne performed this ill-paid task with infinite patience,
sympathy, and self-sacrificing love; and no warrior was ever better
sung in conversational epics than was Carter the successful by
Colburne the disappointed. Under the rude oppression of this subject
the bruised shrub exhaled daily sweetness. It is almost painful to
contemplate these two loving hearts: the one sending its anxious
sympathies a hundred miles away into the deadly trenches of Port
Hudson; the other pouring out its sympathies for a present object,
but covertly and without a thought of reward. If the passionate
affection of the woman is charming, the unrequited, unhoping love
of the man is sublime.
The Doctor perhaps saw what Lillie could not or would not see.
"My dear," he observed, "you must remember that Colonel Carter is
not the husband of Captain Colburne."
"Oh papa!" she answered. "Do you suppose that he doesn't like to
talk about Colonel Carter? Of course he does. He admires him, and
likes him immensely."
"I dare say—I dare say. But nevertheless you give him very large
doses of your husband."
"No, papa; not too large. He is such a good friend that I am sure he
doesn't object. Just think how unkind it would be not to want to talk
about my husband. You don't understand him if you think he is so
shabby."
Nevertheless the Doctor was partially right, and shabby as it may
have been, Colburne was no better for the conversation which so
much gratified Mrs. Carter. His arm discharged its slivers of bone and
healed steadily, but he was thin and pale, slept badly, and had a
slow fever. It must not be supposed that he wilfully brooded over his
disappointment; much less that he was angry about it or felt any
desire to avenge it. He was too sensible not to struggle against
useless pinings; too gentle-hearted and honorable to be even
tempted of base or cruel spirits. Not that he was a moral miracle;
not that he was even a marvellously bright exception to the general
run of humanity; on the contrary he was like many of us, especially
when we are under the influence of elevating emotion. Some by me
forgotten author has remarked that no earthly being is purer, more
like the souls in paradise, than a young man during his first earnest
love.
At one time Colburne entirely forgot himself in his sympathy for Mrs.
Carter. When the news came of the unsuccessful and murderous
assault of the fourteenth of June, she was nearly crazy for three
days because of her uncertainty concerning the fate of her husband.
She must hear constantly from her comforters the assurance that all
was undoubtedly well; that, if the Colonel had been engaged in the
fighting, he would certainly have been named in the official report;
that, if he had received any harm, he would have been all the more
sure of being mentioned, etc., etc. Clinging as if for life to these two
men, she demanded all their strength to keep her out of the depths
of despair. Every day they went two or three times to the fort, one
or other of them, to gather information from passing boats
concerning the new tragedy. Very honestly and earnestly gratified
was Colburne when he was able to bring to Mrs. Carter a letter from
her husband, written the day after the struggle, and saying that no
harm had befallen him. How that letter was wept over, prayed over,
held to a beating heart, and then to loving lips! The house was
solemn all day with that immense and unspeakable joy.
Circumstances soon occurred which caused this lonely and anxious
family to be troubled about its own safety. To carry on the siege of
Port Hudson, Banks had been obliged to reduce the garrison of New
Orleans and of its vast exterior line of defences (a hundred miles
from the city on every side) to the lowest point consistent with
safety. Meantime Taylor reorganized the remnant of his beaten army,
raised new levies by conscription, procured reinforcements from
Texas, and resumed the offensive. Brashear City on the Atchafalaya,
with its immense mass of commissary stores, and garrison of raw
Nine Months' men, was captured by surprise. A smart little battle
was fought at Lafourche Crossing, near Thibodeaux, in which
Greene's Texans charged with their usual brilliant impetuosity, but
were repulsed by our men with fearful slaughter after a hand-to-
hand struggle over the contested cannon. Nevertheless the Union
troops soon retired before superior numbers, and Greene's wild
mounted rangers were at liberty to patrol the Lafourche Interior.
"We can't stay here long," said Colburne, in the council of war in
which the family talked these matters over. "Greene will come this
way sooner or later. If he can take Fort Winthrop, he will thereby
blockade the Mississippi, cut off Banks' supplies, and force him to
raise the siege of Port Hudson. He is sure to try it sooner or later."
"Must we leave our plantation, then?" asked Ravenel in real anguish.
To lose his home, his invested capital, pigs, chickens, prospective
crop of vegetables, and, worse yet, of enlightened and ennobled
negroes, was indeed a torturing calamity. Had he known on the
afternoon of that day, that before morning the shaggy ponies and
long, lank, dirty mosstroopers of Greene's brigade would be upon
him, he would not have paused to examine the situation from so
many different points of view. Colburne knew by experience the
celerity of Texan rangers; he had chased them in forced marches
from Brashear City to Alexandria without ever seeing a tail of their
horses; and yet even he indulged in a false security.
"I think we have twelve hours before us," he observed. "To-morrow
morning we shall have to get up and get, as the natives say. Still it's
my opinion—I don't believe Mrs. Carter had better stay here; she
ought to go to the fort to-night."
"Are you going, papa?" asked Mrs. Carter, who somehow was not
much alarmed.
"My dear, I must stay here till the last moment. We have so much
property here! You will have to go without me."
"Then I won't go," she answered; and so that was settled.
"You ought to be off," said the Doctor to Colburne. "As a United
States officer you are sure to be kept a prisoner, if taken. I certainly
think that you ought to go."
Colburne thought so too, but would not desert his friends; he
shrugged his shoulders in spirit and resolved to endure what might
come. The negroes were in a state of exquisite alarm. The entire
black population of the Lafourche Interior was making for the
swamps or other places of shelter; and only the love of the Ravenel
gang for their good massa and beautiful missus kept them from
being swept away by the contagious current. The horror with which
they regarded the possibility of being returned into slavery delighted
the Doctor, who, even in those circumstances, dilated
enthusiastically upon it as a proof that the race was capable of high
aspirations.
"They have already acquired the love of individual liberty," said this
amiable optimist. "The cognate love of liberty in the abstract, the
liberty of all men, is not far ahead of them. How superior they
already are to the white wretches who are fighting to send them
back to slavery!—Shedding blood, their own and their brothers', for
slavery! Is it not utterly amazing? Risking life and taking life to
restore slavery! It is the foolishest, wickedest, most demoniacal
infatuation that ever possessed humanity. The Inquisition, the
Massacre of St. Bartholomew, were common sense and evangelical
mercy compared to this pro-slavery rebellion. And yet these imps of
atrocity pretend to be Christians. They are the most orthodox
creatures that ever served the devil. They rant and roar in the
Methodist camp-meetings; they dogmatize on the doctrines in the
Presbyterian church; they make the responses in the Episcopal
liturgy. There is only one pinnacle of hypocrisy that they never have
had the audacity to mount. They have not yet brought themselves to
make the continuance and spread of slavery an object of prayer. It
would be logical, you know; it would be just like their impudence. I
have expected that they would come to it. I have looked forward to
the time when their hypocritical priesthood would put up bloody
hands in the face of an indignant Heaven, and say, 'O God of Justice!
O Jesus, lover of the oppressed! bless, extend and perpetuate
slavery; prosper us in selling the wife away from the husband, and
the child away from the parent; enable us to convert the blood and
tears of our fellow creatures into filthy lucre; help us to degrade
man, who was made in Thine image; and to Father, Son and Spirit
be all the Glory!'—Can you imagine anything more astoundingly
wicked than such a petition? And yet I am positively astonished that
they have not got up monthly concerts of prayer, and fabricated a
liturgy, all pregnant with just such or similar blasphemies. But God
would not wait for them to reach this acme of iniquity. His patience
is exhausted, and He is even now bringing them to punishment."
"They have some power left yet, as we feel to-night," said Colburne.
"Yes. I have seen an adder's head flatten and snap ten minutes after
the creature was cut in two. I dare say it might have inflicted a
poisonous wound."
"I think you had better send the hands to the fort."
"Do you anticipate such immediate danger?" inquired the Doctor, his
very spectacles expressing surprise.
"I feel uneasy every time I think of those Texans. They are fast
boys. They outmarch their own shadows sometimes, and have to
wait for them to come in after nightfall."
"I really ought to send the hands off," admitted the Doctor after a
minute of reflection. "I never could forgive myself if through my
means they should be returned to bondage."
"It would be a poor result of a freedman's labor experiment."
The Doctor went to the back door and shouted for Major Scott.
"Major," said he, "you must take all the people down to the fort as
soon as they can get ready."
"They's all ready, Marsr. They's only a waitin' for the word."
"Very well, bring them along. I'll write a note to the commandant,
asking him to take you in for the night. You can come back in the
morning if all is quiet."
"What's a gwine to come of you an' Miss Lillie?"
"Never mind that now. I will see to that presently. Bring the people
along."
In five minutes fifteen men, six women and four pickaninnies, the
whole laboring force of the plantation, were in the road before the
house, each loaded with a portion of his or her property, such as
blankets, food, and cooking utensils. The men looked anxious; the
women cried loudly with fright and grief; the pickaninnies cried
because their mothers did.
"Oh, Mars Ravenel! you'll be cotched suah," sobbed the old mamma
who did the family cooking. "Miss Lillie, do come 'long with us."
"We'se gwine to tote some o' your fixin's 'long," observed Major
Scott.
"Better let him do it," said Colburne. "It may be your only chance to
save necessaries."
So the negroes added to their loads whatever seemed most valuable
and essential of the Ravenel baggage. Then Scott received the note
to the commandant of the fort, handed it to Julius, the second boss,
and remarked with dignity, "I stays with Marsr." The Major was
undisguisedly alarmed, but he had a character to sustain, and a
military title to justify. He was immediately joined in his forlorn hope
by Jim the "no 'count nigger," who, being a sly and limber darkey,
fleet of foot, and familiar with swamp life, had a faith that he could
wriggle out of any danger or captivity.
"Keep them," said Colburne to Ravenel. "We shall want them as
look-outs during the night."
There was an evident hesitation in the whole gang as to whether
they should go or stay; but Colburne settled the question by
pronouncing in a tone of military command, "Forward, march!"
"Ah! they knows how to mind that sort o' talk," said Major Scott,
highly gratified with the spectacular nature of the scene. "I'se a
been eddycatin' 'em to millingtary ways. They knows a heap a'ready,
they doos."
He smiled with a simple and transitory joy, although he could hear
the voice of his wife (commonly called Mamma Major) rising in loud
lament amid the chorus of sorrow with which the women and
children moved away. The poor creature kept no grudge against her
husband for his infidelity of a month previous.
In the lonely and imperilled little household Colburne now took
command.
"Since you will fight," he said smiling, "you must fight under my
orders. I am the military power, and I proclaim martial law."
He forbade the Ravenels to undress; they must be prepared to run
at a moment's notice. He laughed at the Doctor's proposition to
barricade the doors and windows, and, instead thereof, opened two
or three trunks and scattered articles of little value about the rooms.
The property would be a bait, he said, which might amuse the
raiders while the family escaped. To gratify Major Scott's tremulous
enthusiasm he loaded his own revolver and the Doctor's doubled-
barreled fowling-piece, smiling sadly to himself to think how absurd
was the idea of fighting off a band of Texans with such a feeble
artillery. He posted the two negroes as a vidette a quarter of a mile
down the road, with strict orders not to build a fire, not to sleep, not
to make a noise, but in case of the approach of a party to hasten to
the house and give information. The Major begged hard for the
fowling-piece, but Colburne would not let him have it.
"He would be worse than a Nine Months' man," he said to the
Doctor. "He would be banging away at stumps and shadows all
night. There wouldn't be a living field mouse on the plantation by
morning."
The Doctor's imagination was seriously affected by these business-
like preparations, and he silently regretted that he had not gone to
the fort, or at least sent his daughter thither. Lillie, though quiet, was
very pale, and wished herself in the trenches of Port Hudson, safe
under the protection of her invincible husband. Colburne urged and
finally ordered them to lie down and try to sleep. Two mules were
standing in the yard, saddled and ready to do their part in the hegira
when it should be necessary. He examined their harness, then
returned into the house, buckled on his sword and revolver,
extinguished every light, took his seat at an open window looking
towards the danger, waited and listened. The youthful veteran was
perfectly calm; notwithstanding that he had taken more precautions
than a greenhorn, however timorous, would have thought of. Once
in each hour he visited the negroes to see if they were awake; then
mounted the levee to listen for tramp of men or horses across the
bayou; then went to the sugar-house and listened towards the
woods which backed the plantation; then resumed his silent watch
at the open window. At two o'clock the moon still poured a pale light
over the flat landscape. Colburne, feverish with fatigue, want of
sleep, and the small remainder of irritation in his wound, was just
saying to himself, "We must go to-morrow," when he saw two dark
forms glide rapidly towards the house under cover of a fence, and
rush crouching across the door-yard. Without waiting to hear what
the negroes had to say, he stepped into the parlor and awoke the
two sleepers on the sofas.
"What is the matter?" gasped the Doctor, with the wild air common
to people startled out of an anxious slumber.
"Perhaps nothing," answered Colburne. "Only be ready."
By this time the two videttes were in the house, breathless with
running and alarm.
"Oh, Cap'm! they's a comin'," whispered Scott. "They's a comin' right
smart. We heerd the hosses. They's a quarter mile off, mebbe; but
they's a comin' right smart. Oh Cap'm, please give me the double-
barril gun. I wants to fight for my liberty an' for Mars Ravenel an' for
Miss Lillie."
"Take it," said Colburne. "Now then, Doctor, you and Jim will hurry
Mrs. Carter directly down the road to the fort. Jim can keep up on
foot. The Major and I will go to the woods, fire from there, and draw
the enemy in that direction."
Every one obeyed him without a word. The approaching tramp of
horses was distinctly audible at the house when the Ravenels
mounted the mules and set off at a lumbering trot, the animals
being urged forward by resounding whacks from Jim's bludgeon.
Colburne scowled and grated his teeth with impatience and vexation.
"I ought to have sent them away last evening," he muttered with a
throb of self-reproach.
"Scott, you and I will have to fight," he said aloud. "They never can
escape unless we keep the rascals here. We must fire once from the
house; then run to the woods and fire again there. We must show
ourselves men now."
"Yes, Mars Cap'm," replied the Major. His voice was tremulous, and
his whole frame shook, but he was nevertheless ready to die, if need
be, for his liberty and his benefactors. Of physical courage the poor
fellow had little; but in moral courage he was at this moment
sublime.
Colburne posted himself and his comrade at a back corner of the
house, where they could obtain a view of the road which led toward
Thibodeaux.
"Now, Scott," he said, "you must not fire until I have fired. You must
not fire until you have taken aim at somebody. You must fire only
one barrel. Then you must make for the woods along the line of this
fence. If they follow us on horseback we can bother them by
dodging over the fence now and then. If they catch us, we must
fight as long as we can. Cheer up, old fellow. It's all right. It's not
bad business as soon as you're used to it."
"Cap'm, I'se ready," answered Scott solemnly. "I'se not gwine for ter
be cotched alive."
Then he prayed for some minutes in a low whisper, while Colburne
stood at the corner and watched. "Watch and pray," the latter
repeated to himself, smiling inwardly at the odd compliance with the
double injunction, so strangely does the mind work on such
occasions. It was not a deliberate process of intellection with him; it
was an instinctive flash of ideas, not traceable to any feeling which
was in him at the time; on the contrary, his prevailing emotion was
one of extreme anxiety. The tramp which fled toward the fort gently
diminished in the distance, while the tramp which approached from
the opposite side grew nearer and louder. When the advancing
horsemen got within a hundred yards of the house, they slackened
their pace to a walk, and finally halted, probably to listen. Some of
them must have dismounted at this time, for Colburne suddenly
beheld four footmen at the front gate. He scowled at this sign of
experienced caution, and gave a hasty glance toward the garden in
his rear, to see if others were not cutting off his retreat. He could not
discover the features of any of the four, but he could see that they
were of the tall and lank Texan type, dressed in brownish clothing,
and provided with short guns, no doubt double-barreled fowling-
pieces. Inside of the gate they halted and seemed to hearken, while
one of them pointed up the road toward the fort, and whispered to
his comrades. Colburne had hoped that they would get into the
house, and fall to plundering; but they had evidently overheard the
fugitives, for there was a simultaneous backward movement in the
group—they were going to remount and pursue. Now was his time,
if ever, to effect the proposed diversion. Aiming his six-inch revolver
at the tallest, he fired a single barrel. The man yelled a curse,
staggered, dropped his gun, and leaned against the fence. Two of
his comrades sprang across the road, and threw themselves behind
the levee as a breast-work, while the fourth, all grit, turned short
and brought his fowling-piece to a level as Colburne drew behind his
cover. In that same moment, Major Scott, wild with a sudden
madness of conflict, shouted like a lion, bounded beyond the angle
of the house, planting himself on two feet set wide apart, his mad
black face set toward the enemy, and his gun aimed. Both fired at
the same instant, and both fell together, probably alike lifeless. The
last prayer of the negro was, "My God!" and the last curse of the
rebel was "Damnation!"
By the light of the moon Colburne looked at his comrade, and saw
the brains following the blood from a hole in the centre of his
forehead. He cast a glance at the levee, fired one more barrel at a
broad-brimmed hat which rose above it, listened for a second to an
advancing rush of hoofs in order to decide whether it came by the
road or by the fields, turned, crossed the garden on a noiseless run,
placed himself on the further side of a high and close plantation-
fence, and followed its cover rapidly toward the forest. The distance
was less than a quarter of a mile, but he was quite breathless and
faint before he had traversed it, so weak was he still, and so little
accustomed to exercise. In the edge of the wood he sat down on a
fallen and mouldering trunk to listen. If the cavalry were pursuing
their course up the road, they were doing it very prudently and
slowly, for he could hear no more trampling of horses. Tolerably
satisfied as to the safety of the Ravenels, he reloaded his two empty
barrels, settled his course in his mind, and pushed as straight as he
could for Taylorsville without quitting the cover of the forest.
Although the fort was not four miles away in a direct line, it was
daybreak when he came in sight of a low flattened outline, as of a
truncated mound, which showed dimly through the yellowish
morning mist. He had still to cross a dead level of four or five
hundred yards, with no points of shelter but three small wooden
houses. At this moment, when safety seemed so near and sure, he
saw on the bayou road, two hundred yards to his right, half a dozen
black and indistinct bunches moving in a direction parallel to his
own. They were unquestionably horsemen going toward the fort,
and nearer to it than he. Changing his direction, he made straight
for the river, struck it above the fortification, and got behind the
levee, thus securing both a covered way to hide his course, and an
earthwork from behind which he could fight. He lost no time in
peeping over the top of the mound, but pushed ahead at his best
speed, supposing that no cavalry scouts would dare approach very
near to a garrison supplied with artillery. He could see a sentry
pacing the ramparts, the dark uniform showing clear against the
grey sky beyond. He even thought that the man perceived him, and
supposed that his dangers were over for the present. He was full of
exhilaration, and glanced back at the events of the night with a
sense of satisfaction, taking it all for granted with a resolute faith of
satisfaction, that the Ravenels had escaped. Major Scott was dead;
he was really quite sorry for that; but then two Texans had been
killed, or at least disabled; the war was so much nearer its close. In
a small way he felt much as a general does who has effected a
masterly retreat, and inflicted severe loss upon the pursuing enemy.
Presently a break in the bank forced him to mount the levee. As he
reached the top he stared in astonishment and some dismay at a
man in butternut-colored clothing, mounted on a rough pony, with
the double-barreled gun of Greene's mosstroopers across his saddle-
bow, who was posted on the road not forty feet distant. The
Butternut immediately said, in the pleasant way current in armies,
"Halt, you son of a bitch!"
He fired, but missed, as Colburne skirted the break on a run, and
sprang again behind the levee. The Captain then fired in return, with
no other effect than to make the Butternut gallop beyond revolver
range. From this distance he called out, ironically, "I say, Yank, have
you heard from Brashear City?"
Colburne made no reply, but continued his retreat unmolested.
When the sentinel challenged, "Halt! who comes there?" he thought
he had never heard a pleasanter welcome.
"Friend," he answered.
"Halt, friend! Corporal of the guard, number five," shouted the
sentry.
The corporal appeared, recognized Colburne, and let him in through
the gate in a palisade which connected one angle of the fort with the
river. The garrison was already under arms, and the men were lying
down behind the low works, with their equipments on and their
muskets by their sides. The first person from the plantation whom
Colburne saw was Mauma Major.
"Where is Mrs. Carter, aunty?" he asked.
"They's all here, bress the Lord! And now you's come!" shouted the
good fat creature, clapping her hands with delight. "Whar my ole
man?"
"In heaven," said Colburne, with a solemn tenderness which carried
instant conviction. The woman screamed, and went down upon her
knees with an air and face of such anguish as might cast shame
upon those philosophers as have asserted that the negro is not a
man.
"Oh! the Lord gave! The Lord gave!" she repeated, wildly.
Perhaps she had forgotten, perhaps she never knew, the remainder
of the text; but its piteous sense of bereavement, and of more than
human consolation, was evidently clear in some manner to her soul.
CHAPTER XXIII.
CAPTAIN COLBURNE COVERS THE RETREAT OF
THE SOUTHERN LABOR ORGANIZATION.

Colburne soon discovered the Ravenels and their retainers


bivouacked in an angle of the fortification. The Doctor actually
embraced him in delight at his escape; and Mrs. Carter seized both
his hands in hers, exclaiming, "Oh, I am so happy!"
She was full of gayety. She had had a splendid nap; had actually
slept out of doors. Did he see that tent made out of a blanket? She
had slept in that. She could bivouac as well as you, Captain
Colburne; she was as good a soldier as you, Captain Colburne. She
liked it, of all things in the world. She never would sleep in the
house again till she was fif—sixty.
It was curious to note how she checked herself upon the point of
mentioning fifty as the era of first decrepitude. Her father was over
fifty, and therefore fifty could not be old age, notwithstanding her
preconceived opinions on the subject.
"But oh, how obliged we are to you!" she added, changing suddenly
to a serious view. "How kind and noble and brave you are! We owe
you so much!—Isn't it strange that I should be saying such things to
you? I never thought that I should ever say anything of the kind to
any man but my father and my husband. I am indeed grateful to
you, and thankful that you have escaped."
As she spoke, her eyes filled with tears. There was a singular
changeableness about her of late; she shifted rapidly and without
warning, almost without cause, from one emotion to another; she
felt and expressed all emotions with more than usual fervor. She was
sadder at times and gayer at times than circumstances seemed to
justify. An ordinary observer, a man especially, would have been apt
to consider some of her conduct odd, if not irrational. The truth is
that she had been living a new life for the past two months, and that
her being, physical and moral, had not yet been able to settle into a
tranquil unity of function and feeling. Many women and a few men
will understand me here. Colburne was too merely a young man to
comprehend anything; but he could stand a little way off and
worship. He thought, as she faced him with her cheeks flushed and
her eyes the brighter for tears, that she was very near in guise and
nature to an angel. It may be a paradox; it may be a dangerous fact
to make public; but he certainly was loving another man's wife with
perfect innocence.
"What is the matter with Mauma Major?" asked the Doctor.
Colburne briefly related the martyrdom of Scott; and father and
daughter hurried to console the weeping black woman.
Then the young soldier bethought himself that he ought to report his
knowledge of the rebels to the commandant of the garrison. "You'll
find the cuss in there," said a devil-may-care lieutenant, pointing to
a brick structure in the centre of the fort. Colburne entered, saw an
officer sleeping on a pile of blankets, and to his astonishment
recognized him as Major Gazaway. In slumber this remarkable
poltroon looked respectably formidable. He was six feet in height
and nearly two hundred pounds in weight, large-limbed, deep-
chested, broad-shouldered, dark in complexion, aquiline in feature,
masculine and even stern in expression. He had begun life as a prize
fighter, but had failed in that career, not because he lacked strength
or skill, but from want of pluck to stand the hammering.
Nevertheless he was a tolerable hand at a rough-and-tumble fight,
and still more efficient in election-day bullying and browbeating. For
the last ten years he had kept a billiard saloon, had held various
small public offices, and had been the Isaiah Rynders of his little city.
On the stump he had a low kind of popular eloquence made up of
coarse denunciation, slanderous lying, bar-room slang, smutty
stories, and profanity. The Rebellion broke out; the Rebel cannon
aimed at Fort Sumter knocked the breath out of the Democratic
party; and Gazaway turned Republican, bringing over two hundred
fighting voters, and changing the political complexion of his district.
Consequently he easily got a commission as captain in the three
months' campaign, and subsequently as major in the Tenth, much to
the disgust of its commandant. He had expected and demanded a
colonelcy; he thought that the Governor, in not granting it, had
treated him with ingratitude and black injustice; he honestly believed
this, and was naively sore and angry on the subject. It needed this
trait of born impudence to render his character altogether
contemptible; for had he been a conscious, humble coward, he
would have merited a pity not altogether disunited from respect.
From the day of receiving his commission Gazaway had not ceased
to intrigue and bully for promotion in a long series of blotted and ill-
spelled letters. How could a mere Major ever hope to go before the
people successfully as a candidate for Congress? That distinction
was the aim of Gazaway, as of many another more or less successful
blackguard. It is true that these horrid battles occasionally shook his
ambition and his confidence in his own merits. Under fire he was a
meek man, much given to lying low, to praying fervently, to thinking
that a whole skin was better than laurels. But in a few hours after
the danger was past, his elastic vanity and selfishness rose to the
occasion, and he was as pompous in air, as dogmatical in speech, as
impudently greedy in his demands for advancement as ever. Such
was one of Colburne's superior officers; such was the dastard to
whom the wounded hero reported for duty. Colburne, by the way,
had never asked for promotion, believing, with the faith of chivalrous
youth, that merit would be sure of undemanded recognition.
After several calls of "Major!" the slumberer came to his
consciousness; he used it by rolling over on his side, and
endeavoring to resume his dozings. He had not been able to sleep
till late the night before on account of his terrors, and now he was
reposing like an animal, anxious chiefly to be let alone.
"Major—excuse me—I have something of importance to report,"
insisted the Captain.
"Well; what is it?" snarled Gazaway. Then, catching sight of
Colburne, "Oh! that you, Cap? Where you from?"
"From a plantation five miles below, on the bayou. I was followed in
closely by the rebel cavalry. Their pickets are less than half a mile
from the fort."
"My God!" exclaimed Gazaway, sitting up and throwing off his
musquito-net. "What do you think? They ain't going to attack the
fort, be they?" Then calling his homespun pomposity to his aid, he
added, with a show of bravado, "I can't see it. They know better. We
can knock spots out of 'em."
"Of course we can," coincided the Captain. "I don't believe they have
any siege artillery; and if we can't beat off an assault we ought to be
cat-o'-nine-tailed."
"Cap, I vow I wish I had your health," said the Major, gazing
shamelessly at Colburne's thin and pale face. "You can stand
anything. I used to think I could, but this cussed climate fetches me.
I swear I hain't been myself since I come to Louisianny."
It is true that the Major had not been in field service what he once
honestly thought he was. He had supposed himself to be a brave
man; he was never disenchanted of this belief except while on the
battle-field; and after he had run away he always said and tried to
believe that it was because he was sick.
"I was took sick with my old trouble," he continued; "same as I had
at New Orleans, you know—the very day that we attacked Port
Hudson."
By the way, he had not had it at New Orleans; he had had it at
Georgia Landing and Camp Beasland; but Colburne did not correct
him.
"By George! what a day that was!" he exclaimed, referring to the
assault of the 27th of May. "I'll bet more'n a hundred shots come
within five feet of me. If I could a kep' up with the regiment, I'd a
done it. But I couldn't. I had to go straight to the hospital. I tell you
I suffered there. I couldn't get no kind of attention, there was so
many wounded there. After a few days I set out for the regiment,
and found it in a holler where the rebel bullets was skipping about
like parched peas in a skillet. But I was too sick to stand it. I had to
put back to the hospital. Finally the Doctor he sent me to New
Orleans. Well, I was just gettin' a little flesh on my bones when
General Emory ordered every man that could walk to be put to duty.
Nothing would do but I must take command of this fort. I got here
yesterday morning, and the boat went back in the afternoon, and
here we be in a hell of a muss. I brought twenty such invalids along
—men no more fit for duty than I be. I swear it's a shame."
Colburne did not utter the disgust and contempt which he felt; he
turned away in silence, intending to look up dressings for his arm,
which had become dry and feverish. The Major called him back.
"I say, Cap, if the enemy are in force, what are we to do?"
"Why, we shall fight, of course."
"But we ha'n't got men enough to stand an assault."
"How many?"
"One little comp'ny Louisianny men, two comp'nies nine months'
men, and a few invalids."
"That's enough. Have you any spare arms?"
"I d'no. I reckon so," said the Major, in a peevish tone. "I reckon
you'd better hunt up the Quartermaster, if there is one. I s'pose he
has 'em."
"A friend of mine has brought fifteen able-bodied negroes into the
fort. I want guns for them."
"Niggers!" sneered the Major. "What good be they?"
Losing all patience, Colburne disrespectfully turned his back without
answering, and left the room.
"I say, Cap, if we let them niggers fight we'll be all massacred," were
the last words that he heard from Gazaway.
Having got his arm bound anew with wet dressings, he sought out
the Quartermaster, and proceeded to accouter the Ravenel negroes,
meanwhile chewing a breakfast of hard crackers. Then, meeting the
Lieutenant who had directed him to Gazaway's quarters, and who
proved to be the commandant of the Louisiana company, they made
a tour of the ramparts together, doing their volunteer best to take in
the military features of the flat surrounding landscape, and to decide
upon the line of approach which the rebels would probably select in
case of an assault. There was no cover except two or three wooden
houses of such slight texture that they would afford no protection
against shell or grape. The levee on the opposite side of the bayou
might shelter sharpshooters, but not a column. They trained a
twenty-four-pounder iron gun in that direction, and pointed the rest
of the artillery so as to sweep the plain between the fort and a wood
half a mile distant. The ditch was deep and wide, and well filled with
water, but there was no abattis or other obstruction outside of it.
The weakest front was toward the Mississippi, on which side the
rampart was a mere bank not five feet in height, scarcely dominating
the slope of twenty-five or thirty yards which stretched between it
and the water.
"I wish the river was higher—smack up to the fortifications," said the
Louisiana lieutenant. "They can wade around them fences," he
added, pointing to the palisades which connected the work with the
river.
This officer was not a Louisianian by birth, any more than the men
whom he commanded. They were a medley of all nations, principally
Irish and Germans, and he had begun his martial career as a
volunteer in an Indiana regiment. He was chock full of fight and
confidence; this was the only fort he had ever garrisoned, and he
considered it almost impregnable; his single doubt was lest the
assailants "might wade in around them fences." Colburne,
remembering how Banks had been repulsed twice from inferior
works at Port Hudson, also thought the chances good for a defence.
Indeed, he looked forward to the combat with something like a
vindictive satisfaction. Heretofore he had always attacked; and he
wanted to fight the rebels once from behind a rampart; he wanted
to teach them what it was to storm fortifications. If he had been
better educated in his profession he would have found the fort
alarmingly small and open, destitute as it was of bomb-proofs,
casemates and traverses. The river showed no promise of succor;
not a gunboat or transport appeared on its broad, slow, yellow
current; not a friendly smoke could be seen across the flat distances.
The little garrison, it seemed, must rely upon its own strength and
courage. But, after taking a deliberate view of all the circumstances,
Colburne felt justified in reporting to Major Gazaway that the fort
could beat off as many Texans as could stand between it and the
woods, which was the same as to say a matter of one or two
hundred thousand. Leaving his superior officer in a state of
spasmodic and short-lived courage, he spread his rubber blanket in a
shady corner, rolled up his coat for a pillow, laid himself down, and
slept till nearly noon. When he awoke, the Doctor was holding an
umbrella over him.
"I am ever so much obliged to you," said Colburne, sitting up.
"Not at all. I was afraid you might get the fever. Our Louisiana sun,
you know, doesn't dispense beneficence alone. I saw that it had
found you out, and I rushed to the rescue."
"Is Mrs. Carter sheltered?" asked the Captain.
"She is very comfortably off, considering the circumstances."
He was twiddling and twirling his umbrella, as though he had
something on his mind.
"I want you to do me a favor," he said, after a moment. "I should
really like a gun, if it is not too much trouble."
The idea of the Doctor, with his fifty-five years, his peaceful habits,
and his spectacles, rushing to battle made Colburne smile. Another
imaginary picture, the image of Lillie weeping over her father's body,
restored his seriousness.
"What would Mrs. Carter say to it?" he asked.
"I should be obliged if you would not mention it to her," answered
the Doctor. "I think the matter can be managed without her
knowledge."
Accordingly Colburne fitted out this unexpected recruit with a rifle-
musket, and showed him how to load it, and how to put on his
accoutrements. This done, he reverted to the subject which most
interested his mind just at present.
"Mrs. Carter must be better sheltered than she is," he said. "In case
of an assault, she would be in the way where she is, and, moreover,
she might get hit by a chance bullet. I will tell the Major that his
Colonel's wife is here, and that he must turn out for her."
"Do you think it best?" questioned the Doctor. "Really, I hate to
disturb the commandant of the fort."
But Colburne did think it best, and Gazaway was not hard to
convince. He hated to lose his shelter, poor as it was, but he had a
salutary dread of his absent Colonel, and remembering how dubious
had been his own record in field service, he thought it wise to secure
the favor of Mrs. Carter. Accordingly Lillie, accompanied by Black
Julia, moved into the brick building, notwithstanding her late
declarations that she liked nothing so well as sleeping in the open
air.
"Premature old age," laughed Colburne. "Sixty already."
"It is the African Dahomey, and not the American, which produces
the Amazons," observed the Doctor.
"If you don't stop I shall be severe," threatened Lillie. "I have a door
now to turn people out of."
"Just as though that was a punishment," said Colburne. "I thought
out-of-doors was the place to live."
As is usual with people in circumstances of romance which are not
instantly and overpoweringly alarming, there was an exhilaration in
their spirits which tended towards gayety. While Mrs. Carter and
Colburne were thus jesting, the Doctor shyly introduced his martial
equipments into the house, and concealed them under a blanket in
one corner. Presently the two men adjourned to the ramparts, to
learn the cause of a commotion which was visible among the
garrison. Far up the bayou road thin yellow clouds of dust could be
seen rising above the trees, no doubt indicating a movement of
troops in considerable force. From that quarter no advance of
friends, but only of Texan cavalry and Louisianian infantry, could be
expected. Nearly all the soldiers had left their shelters of boards and
rubber blankets, and were watching the threatening phenomenon
with a grave fixedness of expression which showed that they fully
appreciated its deadly significance. Sand-columns of the desert,
water-spouts of the ocean, are a less impressive spectacle than the
approaching dust of a hostile army. The old and tried soldier knows
all that it means; he knows how tremendous will be the screech of
the shells and the ghastliness of the wounds; he faces it with an
inward shrinking, although with a calm determination to do his duty;
his time for elation will not come until his blood is heated by
fighting, and he joins in the yell of the charge. The recruit, deeply
moved by the novelty of the sight, and the unknown grandeur of
horror or of glory which it presages, is either vaguely terrified or full
of excitement. Calm as is the exterior of most men in view of
approaching battle, not one of them looks upon it with entire
indifference. But let the eyes on the fortifications strain as they
might, no lines of troops could be distinguished, and there was little,
if any, increase in the number of the rebel pickets who sat sentinel in
their saddles under the shade of scattered trees and houses.
Presently the murmur "A flag of truce!" ran along the line of
spectators. Down the road which skirted the northern bank of the
bayou rode slowly, amidst a little cloud of dust, a party of four
horsemen, one of whom carried a white flag.
"What does that mean," asked Gazaway. "Do you think peace is
proclaimed?"
"It means that they want this fort," said Colburne. "They are going
to commit the impertinence of asking us to surrender."
The Major's aquiline visage was very pale, and his outstretched hand
shook visibly; he was evidently seized by the complaint which had so
troubled him at Port Hudson.
"Cap, what shall I do?" he inquired in a confidential whisper, twisting
one of his tremulous fingers into Colburne's buttonhole, and drawing
him aside.
"Tell them to go to ——, and then send them there," said the
Captain, angrily, perceiving that Gazaway's feelings inclined toward a
capitulation. "Send out an officer and escort to meet the fellows and
bring in their message. They mustn't be allowed to come inside."
"No, no; of course not. We couldn't git very good terms if they
should see how few we be," returned the Major, unable to see the
matter in any other light than that of his own terrors. "Well, Cap,
you go and meet the feller. No, you stay here; I want to talk to you.
Here, where's that Louisianny Lieutenant? Oh, Lieutenant, you go
out to that feller with jest as many men 's he's got; stop him 's soon
's you git to him, and send in his business. Send it in by one of your
men, you know; and take a white flag, or han'kerch'f, or suthin'."
When Gazaway was in a perturbed state of mind, his conversation
had an unusual twang of the provincialisms of tone and grammar
amidst which he had been educated, or rather had grown up without
an education.
At sight of the Union flag of truce, the rebel one, now only a quarter
of a mile from the fort, halted under the shadow of an evergreen
oak by the roadside. After a parley of a few minutes, the Louisiana
Lieutenant returned, beaded with perspiration, and delivered to
Gazaway a sealed envelope. The latter opened it with fingers which
worked as awkwardly as a worn-out pair of tongs, read the enclosed
note with evident difficulty, cast a troubled eye up and down the
river, as if looking in vain for help, beckoned Colburne to follow him,
and led the way to a deserted angle of the fort.
"I say, Cap," he whispered, "we've got to surrender."
Colburne looked him sternly in the face, but could not catch his
cowardly eye.
"Take care, Major," he said.
Gazaway started as if he had been threatened with personal
violence.
"You are a ruined man if you surrender this fort," pursued Colburne.
The Major writhed his Herculean form, and looked all the anguish
which so mean a nature was capable of feeling; for it suddenly
occurred to him that if he capitulated he might never be promoted,
and never go to Congress.
"What in God's name shall I do?" he implored. "They've got six
thous'n' men."
"Call the officers together, and put it to vote."
"Well, you fetch 'em, Cap. I swear I'm too sick to stan' up."
Down he sat in the dust, resting his elbows on his knees, and his
head between his hands. Colburne sought out the officers, seven in
number, besides himself, and all, as it chanced, Lieutenants.
"Gentlemen," he said, "we are dishonored cowards if we surrender
this fort without fighting."
"Dam'd if we don't have the biggest kind of a scrimmage first,"
returned the Louisianian.
The afflicted Gazaway rose to receive them, opened the
communication of the rebel general, dropped it, picked it up, and
handed it to Colburne, saying, "Cap, you read it."
It was a polite summons to surrender, stating the investing force at
six thousand men, declaring that the success of an assault was
certain, offering to send the garrison on parole to New Orleans, and
closing with the hope that the commandant of the fort would avoid a
useless effusion of blood.
"Now them's what I call han'some terms," broke in Gazaway eagerly.
"We can't git no better if we fight a week. And we can't fight a day.
We hain't got the men to whip six thous'n' Texans. I go for takin'
terms while we can git 'em."
"Gentlemen, I go for fighting," said Colburne.
"That's me," responded the Louisiana lieutenant; and there was an
approving murmur from the other officers.
"This fort," continued our Captain, "is an absolute necessity to the
prosecution of the siege of Port Hudson. If it is lost, the navigation
of the river is interrupted, and our army is cut off from its supplies.
If we surrender, we make the whole campaign a failure. We must
not do it. We never shall be able to face our comrades after it; we
never shall be able to look loyal man or rebel in the eye. We can
defend ourselves. General Banks has been repulsed twice from
inferior works. It is an easy chance to do a great deed—to deserve
the thanks of the army and the whole country. Just consider, too,
that if we don't hold the fort, we may be called on some day to
storm it. Which is the easiest? Gentlemen, I say, No surrender!"
Every officer but Gazaway answered, "That's my vote." The
Louisiana Lieutenant fingered his revolver threatening, and swore by
all that was holy or infernal that he would shoot the first man who
talked of capitulating. Gazaway's mouth had opened to gurgle a
remonstrance, but at this threat he remained silent and gasping like
a stranded fish.
"Well, Cap, you write an answer to the cuss, and the Major'll sign it,"
said the Louisianian to Colburne, with a grin of humorous malignity.
Our friend ran to the office of the Quartermaster, and returned in a
minute with the following epistle:
"Sir: It is my duty to defend Fort Winthrop to the last extremity, and
I shall do it."
The signature which the Major appended to this heroic document
was so tremulous and illegible that the rebel general must have
thought that the commandant was either very illiterate or else a very
old gentleman afflicted with the palsy.
Thus did the unhappy Gazaway have greatness thrust upon him. He
would have been indignant had he not been so terrified; he thought
of court-martialing Colburne some day for insubordination, but said
nothing of it at present; he was fully occupied with searching the
fort for a place which promised shelter from shell and bullet. The
rest of the day he spent chiefly on the river front, looking up and
down the stream in vain for the friendly smoke of gunboats, and
careful all the while to keep his head below the level of the
ramparts. His trepidation was so apparent that the common soldiers
discovered it, and amused themselves by slyly jerking bullets at him,
in order to see him jump, fall down and clap his hand to the part hit
by the harmless missile. He must have suspected the trick; but he
did not threaten vengeance nor even try to discover the jokers:
every feeble source of manliness in him had been dried up by his
terrors. He gave no orders, exacted no obedience, and would have
received none had he demanded it. Late in the afternoon, half a
dozen veritable rebel balls whistling over the fort sent him cowering
into the room occupied by Mrs. Carter, where he appropriated a
blanket and stretched himself at full length on the floor, fairly
grovelling and flattening in search of safety. It was a case of
cowardice which bordered upon mania or physical disease. He had
just manliness enough to feel a little ashamed of himself, and mutter
to Mrs. Carter that he was "too sick to stan' up." Even she, novel as
she was to the situation, understood him, after a little study; and the
sight of his degrading alarm, instead of striking her with a panic,
roused her pride and her courage. With what an admiring contrast of
feeling she looked at the brave Colburne and thought of her brave
husband!
The last rays of the setting sun showed no sign of an enemy except
the wide thin semicircle of rebel pickets, quiet but watchful, which
stretched across the bayou from the river above to the river below.
As night deepened, the vigilance of the garrison increased, and not
only the sentinels but every soldier was behind the ramparts, each
officer remaining in rear of his own company or platoon, ready to
direct it and lead it at the first alarm. Colburne, who was tacitly
recognized as commander-in-chief, made the rounds every hour.
About midnight a murmur of joy ran from bastion to bastion as the
news spread that two steamers were close at hand, coming up the
river. Presently every one could see their engine-fires glowing like
fireflies in the distant, and hear through the breathless night the
sighing of the steam, the moaning of the machinery, and at last the
swash of water against the bows. The low, black hulks, and short,
delicate masts, distinctly visible on the gleaming groundwork of the
river, and against the faintly lighted horizon, showed that they were
gunboats; and the metallic rattle of their cables, as they came to
anchor opposite the fort, proved that they had arrived to take part in
the approaching struggle. Even Gazaway crawled out of his asylum
to look at the cheering reinforcement, and assumed something of his
native pomposity as he observed to Colburne, "Cap, they won't dare
to pitch into us, with them fellers alongside."
A bullet or two from the rebel sharpshooters posted on the southern
side of the bayou sent him back to his house of refuge. He thought
the assault was about to commence, and was entirely absorbed in
hearkening for its opening clamor. When Mrs. Carter asked him what
was going on, he made her no answer. He was listening with all his
pores; his very hair stood on end to listen. Presently he stretched
himself upon the floor in an instinctive effort to escape a spattering
of musketry which broke through the sultry stillness of the night. A
black speck had slid around the stern of one of the gunboats, and
was making for the bank, saluted by quick spittings of fire from the
levee above and below the junction of the bayou with the river. In
reply, similar fiery spittings scintillated from the dark mass of the
fort, and there was a rapid whit-whit of invisible missiles. A cutter
was coming ashore; the rebel pickets were firing upon it; the
garrison was firing upon the pickets; the pickets upon the garrison.
The red flashes and irregular rattle lasted until the cutter had
completed its return voyage. There was an understanding now
between the little navy and the little army; the gunboats knew
where to direct their cannonade so as best to support the garrison;
and the soldiers were full of confidence, although they did not relax
their vigilance. Doctor Ravenel and Mrs. Carter supposed in their
civilian inexperience that all danger was over, and by two o'clock in
the morning were fast asleep.
CHAPTER XXIV.
A DESPERATE ATTACK AND A SUCCESSFUL
DEFENCE.

While it was still darkness Lillie was awakened from her sleep by an
all-pervading, startling, savage uproar. Through the hot night came
tramplings and yellings of a rebel brigade; roaring of twenty-four-
pounders and whirring of grape from the bastions of the fort; roaring
of hundred-pounders and flight of shrieking, cracking, flashing shells
from the gunboats; incessant spattering and fiery spitting of
musketry, with whistling and humming of bullets; and, constant
through all, the demoniac yell advancing like the howl of an infernal
tide. Bedlam, pandemonium, all the maniacs of earth and all the
fiends of hell, seemed to have combined in riot amidst the crashings
of storm and volcano. The clamor came with the suddenness and
continued with more than the rage of a tornado. Lillie had never
imagined anything so unearthly and horrible. She called loudly for
her father, and was positively astonished to hear his voice close at
her side, so strangely did the familiar tones sound in that brutal
uproar.
"What is it?" she asked.
"It must be the assault," he replied, astonished into telling the
alarming truth. "I will step out and take a look."
"You shall not," she exclaimed, clutching him. "What if you should be
hit!"
"My dear, don't be childish," remonstrated the Doctor. "It is my duty
to attend to the wounded. I am the only surgeon in the fort. Just
consider the ingratitude of neglecting these brave fellows who are
fighting for our safety."
"Will you promise not to get hurt?"
"Certainly, my dear."
"Will you come back every five minutes and let me see you?"
"Yes, my dear. I'll keep you informed of everything that happens."
She thought a few moments, and gradually loosened her hold on
him. Her curiosity, her anxiety to know how this terrible drama went
on, helped her to be brave and to spare him. As soon as her fingers
had unclosed from his sleeve he crept to where his rifle stood and
softly, seized it; and in so doing he stepped on the recumbent
Gazaway, who groaned, whereupon the Doctor politely apologized.
As he stepped out of the building he distinguished Colburne's voice
on the river front, shouting, "This way, men!" In that direction ran
the Doctor, holding his rifle in both hands, at something like the
position of a charge bayonet, with his thumb on the trigger so as to
be ready for immediate conflict. Suddenly bang! went the piece at
an angle of forty-five degrees, sending its ball clean across the
Mississippi, and causing a veteran sergeant near him to inquire
"what the hell he was about."
"Really, that explosion was quite extraordinary," said the surprised
Doctor. "I had not the least intention of firing. Would you, sir, have
the goodness to load it for me?"
But the sergeant was in a hurry, and ran on without answering. The
Doctor began to finger his cartridge-box in a wild way, intending to
get out a cartridge if he could, when a faint voice near him said, "I'll
load your gun for you, sir."
"Would you be so kind?" replied the Doctor, delighted. "I am so
dreadfully inexperienced in these operations! I am quite sorry to
trouble you."
The sick man—one of the invalids whom Gazaway had brought from
New Orleans—loaded the piece, capped it, and added some brief
instructions in the mysteries of half-cock and full-cock.
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

You might also like