




























































































Estude fácil! Tem muito documento disponível na Docsity
Ganhe pontos ajudando outros esrudantes ou compre um plano Premium
Esta página não é visível na pré-visualização
Não perca as partes importantes!





























































































Learn Android Studio 4
Efficient Java-Based
Android Apps Development
Second Edition
v
Table of Contents
History ........................................................................................................................................... 1 The Operating System................................................................................................................... 3 Summary....................................................................................................................................... 5
Setup ............................................................................................................................................. 7 Configuring Android Studio ......................................................................................................... 10 Hardware Acceleration ................................................................................................................ 14 Summary..................................................................................................................................... 15
Create a Project .......................................................................................................................... 17 Create an AVD ............................................................................................................................. 22 Summary..................................................................................................................................... 29
The IDE ........................................................................................................................................ 31 Main Editor .................................................................................................................................. 34 Editing Layout Files ..................................................................................................................... 35 TODO Items ................................................................................................................................. 38
- How to Get More Screen Space for Codes - Project Tool Window - Preferences/Settings - Summary..................................................................................................................................... xi
About the Author
Ted Hagos is a software developer by trade. At the moment, he’s Chief Technology Officer and Data Protection Officer of RenditionDigital International, a software development company based out of Dublin. He wore many hats in his 20+ years in software development, for example, team lead, project manager, architect, and director for development. He also spent time as a trainer for IBM Advanced Career Education, Ateneo ITI, and Asia Pacific College.
xv
Acknowledgments
To Stephanie and Adrianne, my thanks and my love. To Mark Powers and Steve Anglin, and to all who made this book possible. Many, many thanks.
xvii
Introduction
Welcome to Learn Android Studio 4. This book will help you get started in your programming journey with the little green robot. You already bought the book (many thanks to you), so you don’t need to be convinced that programming for the mobile platform offers many opportunities for software developers. The book is aimed at beginning Android programmers but not wholly new to programming. The book assumes that you have prior programming experience with any of the CFOL (C family of languages, e.g., C, C++, Java, C#, JavaScript). Ideally, you are already a Java programmer trying to get your feet wet in Android; if you’re not, don’t worry. Basic Java programming is covered in the Appendix, and you can refer to that as you try to feel your way into the language. The book covers two fronts: the fundamentals of Android programming and the use of Android Studio 4. Android programming concepts and the use of the IDE are explained using a combination of graphics and code walk-throughs: there’s plenty of those in the book.
Chapter Overview
Chapter 1 : Android Overview —This chapter introduces Android. It deals with a bit of Android’s history and the technical makeup of its OS. Chapter 2 : Android Studio —If you haven’t set up your Android environment yet, don’t skip this chapter; it walks you through the setup of Android Studio, whether you’re on macOS, Windows, or Linux. It also introduces the essential parts of the IDE. Chapter 3 : Project Basics —This chapter introduces the concept and mechanics of an Android project. It walks through creating a project and running a project in an AVD (Android Virtual Device).
xix
Chapter 13 : Testing —At some point, you have to test your code before you release them. This chapter introduces you to the many kinds of testing you can do to an app. More importantly, it introduces you to unit testing and Espresso testing.
Chapter 14 : Working with Files —You’ll need to save to a text file or read from it; this chapter walks through the basics of file input and output in Android.
Chapter 15 : BroadcastReceivers —One of Android’s foundational components is the BroadcastReceiver; this component lets you build decoupled apps by adopting the publish-subscribe pattern.
Chapter 16 : Jetpack, LiveData, ViewModel, and Room —More goodies from Architecture components. This chapter walks through the basics of how to build components that have lifecycle awareness of other components and how to use Room.
Chapter 17 : Distributing Apps —When you’re ready to distribute your app, you’ll need to sign it and list it in a marketplace like Google Play. This chapter walks you through the steps on how to do it.
Chapter 18 : Short Takes —More Android Studio goodness.
Appendix —The Appendix breezes through the Java language. It deals with some of the basic language concepts you will need to get started in Android programming.
INTRODUCTION
© Ted Hagos 2020^1 T. Hagos, Learn Android Studio 4 , https://doi.org/10.1007/978-1-4842-5937-5_
Android Overview
What the chapter covers:
History
2003. Andy Rubin founded Android Inc.; Google backed the company but didn’t own yet. 2005. Google bought Android Inc 2007. Android was officially given to open source; Google turned over the ownership to the Open Handset Alliance (OHA). 2008. Android v1.0 was released. The Google Play Store was called by a different name then; it was called the “Market.” 2009. Versions 1.1, 1.5 (Cupcake), 1.6 (Donut), and 2.0 (Eclair) were released. Cupcake was the first version to get the sugary treats naming scheme. This was a significant release because it featured an on-screen keyboard. Donut is remembered as the first version to include the “search box.” Eclair is remembered as the first to include Google maps, which started the death of built-in car navigation, because Google offered Maps for free.
2015. Versions 6.0 and 6.01 (Marshmallow) were released. The app menu changed dramatically, and Google added search bar so users can find apps quickly. The memory managers were introduced in this version so users can check the memory usage of apps. The permission system was revamped as well; apps can no longer request for permissions on a wholesale basis; permissions were requested (and granted) on a per-permission basis and as they were required. 2016. Versions 7.0–7.1.2 (Nougat) were released. “Google Now” was replaced with “Google Assistant.” The improved multitasking system allowed for split-screen mode. 2017. Versions 8.0 and 8.1 (Oreo) were released; and with it were more multitasking features. Picture-in-picture and native split- screen was introduced with this version. 2018. Android 9.0 (Pie) was released—exactly 10 years after v1.0. This release brought with it quite a number of visual changes which made it the most significant update in recent years. The three-button setup was replaced with a single-pill shaped button and gestures to control things like multitasking. 2019. Android 10 was released; this is a shift for Google in terms of naming the versions. Google did away with the dessert names and simply named the version according to its number. The green robot is being rebranded. This version also marks the end of the Android navigation buttons. While Android 9 kept the “back” button, v10 has completely removed it and will use gestures instead.
The Operating System
The most visible part of Android, at least for developers, is its operating system. Android OS may appear complex, but its purpose is simple; it stands between the user and the hardware. That may be an oversimplification, but it will suffice for our purposes. By “user,” I don’t literally mean an end user or a person; by “user” I mean an application, a piece of code that a programmer creates, like a word processor or an email client.
CHAPTER 1 ANDROID OVERVIEW
Take the email app, for example; as you type each character, the app needs to communicate to the hardware for the message to make its way to your screen and hard drive and eventually send it to the cloud via your network. It’s a more involved process than I describe it here, but that is the basic idea. At its simplest, an OS does three things:
The lowest level in the diagram is the one responsible for interfacing with the hardware, various services like memory management, and executions of processes. This part of the Android OS is Linux. Linux is a very stable OS and is quite ubiquitous itself. You can find it in many places like server hardware on data centers, appliances, medical devices, and so forth. Android uses Linux which handles hardware interfacing and some other kernel functions.
CHAPTER 1 ANDROID OVERVIEW