Introduction 1 How to Use This Book 1 Conventions Used in This Book 2 Foolish Assumptions 2 Icons Used in This Book 3 Beyond the Book 4 Where to Go from Here 4 Book 1: Getting Started with Android Application Development 5 Chapter 1: All about Android 7 The Consumer Perspective 8 The Versions of Android 9 The Developer Perspective 12 Java and Kotlin 12 XML 14 Linux 16 The Business Perspective 18 Chapter 2: Installing the Software Tools 19 Setting Up the Software 20 Considering the requirements 20 Downloading the software 21 Installing Android Studio 23 Installing offline tools 25 Launching the Android Studio IDE 28 In Windows 29 On a Mac 29 In Linux 30 In Chrome OS 30 Using the Android Studio Setup Wizard 30 Fattening Up the Android SDK 32 The more things stay the same, the more they change 32 Installing new versions (and older versions) of Android 33 Creating an Android virtual device 35 A third-party emulator 39 Chapter 3: Creating an Android App 43 Creating Your First App 43 Starting the IDE and creating your first app 45 Launching your first app 50 Running Your App 52 You Can Download All the Code 55 Troubleshooting Common IDE Errors 58 Error message: Failed to find target 58 Error running ''app'': No target device found 58 Error message: Android Virtual Device may be incompatible with your configuration 58 You lose contact with the Android Debug Bridge (ADB) 59 You don''t like whatever AVD opens automatically 59 The emulator stalls during startup 60 Error message: The user data image is used by another emulator 61 Error message: Unknown virtual device name 63 The emulator displays a "process isn''t responding" dialog box 63 Changes to your app don''t appear in the emulator 64 Testing Apps on a Real Device 64 Chapter 4: Examining a Basic Android App 67 A Project''s Files 68 The MainActivity.kt file 71 The onCreate() method 72 Using other templates 73 The res Branch 76 The res/drawable branch 77 The res/layout branch 77 The res/menu branch 78 The res/mipmap branch 79 The res/values branch 80 Other Files in an Android Project 82 The build.gradle file 82 The AndroidManifest.xml file 85 The R.java file 87 The assets folder 89 The android.jar archive 90 The APK file 91 What Did I Agree To? 93 What''s in a name? 93 Choosing a language 95 Your app''s API levels 95 Chapter 5: Conjuring and Embellishing an Android App 101 Dragging, Dropping, and Otherwise Tweaking an App 102 Creating the "look" 102 Coding the behavior 112 A Bit of Debugging 118 Try it! 118 Discovering the secrets of Logcat 123 Using the debugger 126 Chapter 6: Improving Your App 131 Improving the Layout 131 Changing the layout 132 Creating a reusable layout 139 Reusing a layout 142 Starting Another Activity 145 Localizing Your App 151 Responding to Check Box Events 155 Displaying Images 157 Sending in Your Order 162 Book 2: Android Background Material 167 Chapter 1: Using Android Studio 169 Good to Know versus Need to Know 170 Getting a Feel for the Big Picture 171 The main window 173 Viewing modes 179 The Designer tool 181 Discovering What You Can Do 184 Finding things 185 Fixing code 190 Refactoring 199 Chapter 2: Kotlin for Java Programmers 203 Using Kotlin or Java for Development 204 Defining the Java Issues That Kotlin Fixes 207 Improving control over null references 207 Removing raw data types 210 Using invariant arrays 210 Working with proper function types 212 Getting rid of the checked exceptions 213 Nothing''s Perfect: Kotlin is Missing Features, Too 214 Considering primitive types that are not classes 214 Losing static members 214 Eliminating non-private fields 215 Reducing confusion by eliminating wildcard-types 216 Abandoning the ternary-operator a ? b : c 217 Looking at What Kotlin Adds to the Picture 218 Considering higher order functions and lambdas 218 Refining object orientation using extension functions 218 Relying on smart casts 219 Employing string templates 220 Understanding primary constructors 221 Implementing first-class delegation 221 Using ranges of values 223 Creating data classes 224 Overloading operators 224 Developing asynchronous code using coroutines 225 Chapter 3: Kotlin for Everyone 227 Moving from Development to Execution with Kotlin 228 What is a compiler? 228 Understanding native code compiler or interpreter issues 230 Considering the Android Runtime (ART) 231 Grasping Kotlin Code 235 Nearly everything begins with an expression 236 The Kotlin class 238 Classes and objects 239 Kotlin types 240 Performing casts 245 The Kotlin function 249 Objects and their constructors 252 Classes grow on trees 254 The Kotlin package 255 Considering Kotlin visibility rules 257 Defying your parent 258 Kotlin comments 259 Chapter 4: What Kotlin Does (and When) 261 Making Decisions (Kotlin if Statements) 261 Testing for equality 264 Choosing among many alternatives (Kotlin when statements) 266 Repeating Instructions Over and Over Again 269 Kotlin while statements 269 Kotlin do statements 271 Arrays in Kotlin 273 Kotlin''s for statements 277 Looping using Kotlin recursion 281 Working with break and continue 283 Jumping Away from Trouble 284 Working with Kotlin Collections 286 Considering the collection types 287 Differentiating between read-only and mutable collections 289 Chapter 5: Object-Oriented Programming in Kotlin 291 Static Fields and Methods 291 Interfaces and Callbacks 294 Event handling and callbacks 299 An object remembers who created it 302 A less wordy way to implement an interface 303 Classes That Must (and Must Not) Be Extended 305 The need to override 306 Java''s final classes 306 Kotlin''s open classes 307 Kotlin extensions 307 Abstract classes 308 Inner Classes 310 Named inner classes 310 Anonymous inner classes 312 Chapter 6: Functional Programming in Kotlin 315 Defining Functional Programming 316 Differences from other programming paradigms 316 Understanding its goals 317 Understanding Pure and Impure Languages 318 Using the pure approach 318 Using the impure approach 320 Comparing the Functional Paradigm 320 Using Kotlin for Functional Programming Needs 322 Defining the Role of State 323 Using Recursion to Perform Calculations 324 Relying on standard recursion 324 Relying on tail recursion 326 Using Function Types 327 Understanding Function Literals 329 Lambda expressions 329 Anonymous functions 330 Defining the Function Types 331 Comprehensions 331 Receivers 332 Inline 334 Utility 335 Using Functional Programming for Android Apps 336 Chapter 7: A Look at XML 339 XML Isn''t Ordinary Text 340 Of tags and elements 340 Other things you find in an XML document 348 What''s in a Namespace? 350 The package attribute 353 The style attribute 354 Book 3: The Building Blocks 357 Chapter 1: Getting an Overview of Jetpack 359 Understanding the Benefits of Jetpack 360 Eliminating boilerplate code 360 Managing background tasks 361 Navigating between activities and fragments 362 Managing memory 364 Performing configuration changes 365 Considering the Jetpack Components 366 Foundation 367 Architecture 368 Behavior 370 UI 372 Getting an Overview of the AndroidX Package 373 Working with Lifecycle-Aware Components 374 Focusing on activities 375 Understanding events and states 376 Chapter 2: Building a Foundation for Your App 377 Working with Android KTX 378 Getting a feel for KTX features 378 Using KTX in your project 381 Considering the modules 382 Addressing Security Issues 389 Benchmarking Your Application 392 Removing barriers to correct results 393 Creating a test app 394 Profiling your app 397 Tracing your app 398 Checking for benchmarking module support 400 Benchmarking the app 401 Testing Application Functionality 403 Chapter 3: Creating an Architecture 405 Managing Application Activities 405 Defining an activity 406 Getting an overview of intent filters 407 Considering the activity lifecycle 407 Understanding the backstack 409 Working with fragments 412 Considering the fragment lifecycle 416 Seeing activities and fragments in action 417 Providing for Navigational Need.
Android Application Development All-In-One for Dummies