Android Studio 3.0 Development Essentials

Transcription

Android Studio 3.0Development EssentialsAndroid 8 Edition

Android Studio 3.0 Development Essentials – Android 8 EditionISBN-13: 978-1977540096 2017 Neil Smyth / Payload Media, Inc. All Rights Reserved.This book is provided for personal use only. Unauthorized use, reproduction and/or distribution strictlyprohibited. All rights reserved.The content of this book is provided for informational purposes only. Neither the publisher nor the authoroffers any warranties or representation, express or implied, with regard to the accuracy of informationcontained in this book, nor do they accept any liability for any loss or damage arising from any errors oromissions.This book contains trademarked terms that are used solely for editorial purposes and to the benefit of therespective trademark owner. The terms used within this book are not intended as infringement of anytrademarks.Rev: 1.0

Table of Contents1. Introduction . 11.1 Downloading the Code Samples . 11.2 Download the eBook . 21.3 Firebase Essentials Book now Available . 21.4 Feedback . 21.5 Errata . 32. Setting up an Android Studio Development Environment . 52.1 System Requirements . 52.2 Downloading the Android Studio Package . 52.3 Installing Android Studio. 62.3.1 Installation on Windows . 62.3.2 Installation on macOS. 62.3.3 Installation on Linux . 72.4 The Android Studio Setup Wizard . 72.5 Installing Additional Android SDK Packages . 82.6 Making the Android SDK Tools Command-line Accessible . 102.6.1 Windows 7 . 112.6.2 Windows 8.1 . 122.6.3 Windows 10 . 122.6.4 Linux . 132.6.5 macOS. 132.7 Updating Android Studio and the SDK . 132.8 Summary . 133. Creating an Example Android App in Android Studio . 153.1 Creating a New Android Project . 153.2 Defining the Project and SDK Settings . 163.3 Creating an Activity . 173.4 Modifying the Example Application . 193.5 Reviewing the Layout and Resource Files . 263.6 Summary . 294. A Tour of the Android Studio User Interface . 314.1 The Welcome Screen . 314.2 The Main Window. 324.3 The Tool Windows . 334.4 Android Studio Keyboard Shortcuts . 364.5 Switcher and Recent Files Navigation . 37i

4.6 Changing the Android Studio Theme . 384.7 Summary . 385. Creating an Android Virtual Device (AVD) in Android Studio . 395.1 About Android Virtual Devices . 395.2 Creating a New AVD . 405.3 Starting the Emulator . 415.4 Running the Application in the AVD . 425.5 Run/Debug Configurations . 435.6 Stopping a Running Application . 455.7 AVD Command-line Creation . 465.8 Android Virtual Device Configuration Files . 475.9 Moving and Renaming an Android Virtual Device . 485.10 Summary . 486. Using and Configuring the Android Studio AVD Emulator . 496.1 The Emulator Environment. 496.2 The Emulator Toolbar Options . 506.3 Working in Zoom Mode . 516.4 Resizing the Emulator Window. 516.5 Extended Control Options . 516.5.1 Location . 526.5.2 Cellular . 526.5.3 Battery . 526.5.4 Phone. 526.5.5 Directional Pad . 536.5.6 Microphone . 536.5.7 Fingerprint . 536.5.8 Virtual Sensors . 536.5.9 Settings . 536.5.10 Help . 536.6 Drag and Drop Support . 536.7 Configuring Fingerprint Emulation . 546.8 Summary . 557. Testing Android Studio Apps on a Physical Android Device . 577.1 An Overview of the Android Debug Bridge (ADB) . 577.2 Enabling ADB on Android based Devices . 577.2.1 macOS ADB Configuration . 587.2.2 Windows ADB Configuration . 597.2.3 Linux adb Configuration . 607.3 Testing the adb Connection . 61ii

7.4 Summary . 628. The Basics of the Android Studio Code Editor . 638.1 The Android Studio Editor . 638.2 Splitting the Editor Window. 668.3 Code Completion . 668.4 Statement Completion . 688.5 Parameter Information . 688.6 Parameter Name Hints . 688.7 Code Generation . 688.8 Code Folding . 708.9 Quick Documentation Lookup . 718.10 Code Reformatting. 718.11 Finding Sample Code . 728.12 Summary . 739. An Overview of the Android Architecture . 759.1 The Android Software Stack . 759.2 The Linux Kernel . 769.3 Android Runtime – ART . 779.4 Android Libraries. 779.4.1 C/C Libraries . 789.5 Application Framework . 789.6 Applications . 799.7 Summary . 7910. The Anatomy of an Android Application . 8110.1 Android Activities . 8110.2 Android Intents . 8210.3 Broadcast Intents . 8210.4 Broadcast Receivers . 8210.5 Android Services . 8210.6 Content Providers . 8310.7 The Application Manifest . 8310.8 Application Resources. 8310.9 Application Context . 8310.10 Summary . 8411. Understanding Android Application and Activity Lifecycles . 8511.1 Android Applications and Resource Management . 8511.2 Android Process States . 8611.2.1 Foreground Process . 8611.2.2 Visible Process . 86iii

11.2.3 Service Process . 8611.2.4 Background Process . 8711.2.5 Empty Process . 8711.3 Inter-Process Dependencies . 8711.4 The Activity Lifecycle . 8711.5 The Activity Stack . 8711.6 Activity States . 8811.7 Configuration Changes . 8911.8 Handling State Change. 8911.9 Summary . 8912. Handling Android Activity State Changes . 9112.1 The Activity Class . 9112.2 Dynamic State vs. Persistent State . 9312.3 The Android Activity Lifecycle Methods . 9412.4 Activity Lifetimes . 9612.5 Disabling Configuration Change Restarts . 9712.6 Summary . 9713. Android Activity State Changes by Example . 9913.1 Creating the State Change Example Project . 9913.2 Designing the User Interface . 10013.3 Overriding the Activity Lifecycle Methods . 10113.4 Filtering the Logcat Panel . 10513.5 Running the Application . 10613.6 Experimenting with the Activity . 10713.7 Summary . 10814. Saving and Restoring the State of an Android Activity . 10914.1 Saving Dynamic State . 10914.2 Default Saving of User Interface State . 10914.3 The Bundle Class . 11114.4 Saving the State . 11114.5 Restoring the State . 11314.6 Testing the Application . 11314.7 Summary . 11415. Understanding Android Views, View Groups and Layouts . 11515.1 Designing for Different Android Devices . 11515.2 Views and View Groups . 11515.3 Android Layout Managers . 11615.4 The View Hierarchy . 11715.5 Creating User Interfaces . 119iv

15.6 Summary . 11916. A Guide to the Android Studio Layout Editor Tool . 12116.1 Basic vs. Empty Activity Templates . 12116.2 The Android Studio Layout Editor . 12416.3 Design Mode . 12416.4 The Palette . 12516.5 Pan and Zoom . 12616.6 Design and Layout Views . 12616.7 Text Mode . 12716.8 Setting Attributes . 12816.9 Configuring Favorite Attributes . 13016.10 Creating a Custom Device Definition . 13116.11 Changing the Current Device . 13216.12 Summary . 13217. A Guide to the Android ConstraintLayout . 13317.1 How ConstraintLayout Works . 13317.1.1 Constraints . 13317.1.2 Margins . 13417.1.3 Opposing Constraints . 13417.1.4 Constraint Bias . 13517.1.5 Chains . 13617.1.6 Chain Styles . 13717.2 Baseline Alignment . 13717.3 Working with Guidelines. 13817.4 Configuring Widget Dimensions . 13917.5 Working with Barriers . 13917.6 Ratios . 14117.7 ConstraintLayout Advantages . 14117.8 ConstraintLayout Availability . 14117.9 Summary . 14118. A Guide to using ConstraintLayout in Android Studio . 14318.1 Design and Layout Views . 14318.2 Autoconnect Mode . 14518.3 Inference Mode . 14518.4 Manipulating Constraints Manually . 14618.5 Adding Constraints in the Inspector . 14718.6 Deleting Constraints . 14718.7 Adjusting Constraint Bias . 14818.8 Understanding ConstraintLayout Margins . 149v

18.9 The Importance of Opposing Constraints and Bias . 15018.10 Configuring Widget Dimensions . 15318.11 Adding Guidelines . 15418.12 Adding Barriers .

Android Studio 3.0 Development Essentials – Android 8 Edition ISBN-13: 978-1977540096 2