Complete Download Learn Android Studio 4 - Efficient Java-Based Android Apps Development 2nd Edition Ted Hagos PDF All Chapters
Complete Download Learn Android Studio 4 - Efficient Java-Based Android Apps Development 2nd Edition Ted Hagos PDF All Chapters
com
https://textbookfull.com/product/learn-android-
studio-4-efficient-java-based-android-apps-development-2nd-
edition-ted-hagos/
OR CLICK BUTTON
DOWNLOAD NOW
https://textbookfull.com/product/learn-android-studio-3-efficient-
android-app-development-1st-edition-ted-hagos/
textboxfull.com
https://textbookfull.com/product/beginning-android-games-development-
from-beginner-to-pro-4th-edition-ted-hagos/
textboxfull.com
https://textbookfull.com/product/beginning-android-games-development-
from-beginner-to-pro-4th-edition-ted-hagos-2/
textboxfull.com
Learn Java for Android Development Friesen Jeff
https://textbookfull.com/product/learn-java-for-android-development-
friesen-jeff/
textboxfull.com
https://textbookfull.com/product/android-studio-3-0-development-
essentials-android-8-edition-neil-smyth/
textboxfull.com
Ted Hagos
Learn Android Studio 4: Efficient Java-Based Android Apps Development
Ted Hagos
Manila, National Capital Region, Philippines
Acknowledgments ...................................................................................................xv
Introduction ...........................................................................................................xvii
v
TABLE OF CONTENTS
vi
TABLE OF CONTENTS
viii
TABLE OF CONTENTS
ix
TABLE OF CONTENTS
x
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.
xi
About the Technical Reviewer
Jeff Friesen is a freelance teacher and software developer
with an emphasis on Java. In addition to authoring Java I/O,
NIO and NIO.2 (Apress) and Java Threads and the Concurrency
Utilities (Apress), Jeff has written numerous articles on
Java and other technologies (such as Android) for JavaWorld
(www.javaworld.com), InformIT (www.informit.com),
Java.net, SitePoint (www.sitepoint.com), and other
websites. Jeff can be contacted via his website at JavaJeff.ca
or via his LinkedIn profile (www.linkedin.com/in/javajeff).
xiii
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.
xv
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.
xvii
INTRODUCTION
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.
xix
CHAPTER 1
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.
1
© Ted Hagos 2020
T. Hagos, Learn Android Studio 4, https://doi.org/10.1007/978-1-4842-5937-5_1
CHAPTER 1 ANDROID OVERVIEW
2
CHAPTER 1 ANDROID OVERVIEW
3
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:
Figure 1-1 shows a logical diagram of Android’s system architecture; it is far from
complete, since it doesn’t show all the apps, components, and libraries in the Android
platform, but it should give you an idea on how things are organized.
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.
4
CHAPTER 1 ANDROID OVERVIEW
On top of the Linux kernel are low-level libraries like SQLite, OpenGL, and so on.
These are not part of the Linux kernel but are still low level and as such are written
mostly in C/C++. On the same level, you will find the Android Runtime which is where
Android applications are run.
Next up is the application framework layer. It sits on top of both the low-level
libraries and the Android Runtime because it needs both. This is the layer that we will
interact with as an application developer because it contains all the libraries we need to
write apps.
Finally, on top is the application layer. This is where all our apps reside, both the
ones we write and the ones that come prebuilt with the OS. It should be pointed out that
prebuilt applications which come with the device do not have any special privileges over
the ones we will write. If you don’t like the email app of the phone, you can write your
own and replace it. Android is democratic like that.
Summary
• Android has gone a long way, from the clunky Cupcake version to
Android 10, which is very advanced and provides a buttery smooth
user experience. Android’s release cadence was frenetic during the
early years, but it has since subsided and settled on a more uniform
12-month cycle.
5
CHAPTER 2
Android Studio
What the chapter covers:
Setup
At the time of writing, Android Studio 4 was on preview release; the version I used for
this book was Canary 9. Android Studio 4 might be on stable release by the time you’re
reading this book; hopefully, the diagrams and screenshots won’t be too different
by then. To download Android Studio 4 (preview release), you can go to https://
developer.android.com/studio/preview.
The installer is available for Windows (both 32- and 64-bit), macOS, and Linux. I ran
the installation instructions on macOS (Catalina), Windows 10 64-bit, and Ubuntu 18. I
work primarily in a macOS environment, which explains why most of the screen grabs
for this book look like macOS. Android Studio looks, runs, and feels (mostly) the same in
7
© Ted Hagos 2020
T. Hagos, Learn Android Studio 4, https://doi.org/10.1007/978-1-4842-5937-5_2
CHAPTER 2 ANDROID STUDIO
all three platforms, with very minor differences like key bindings and the main menu bar
in macOS.
Before we go further, let’s look at the system requirements for Android Studio; at a
minimum, you’ll need either of the following:
The preceding list came from the official Android website (https://developer.
android.com/studio); of course, more is better.
There are no prerequisite software for Android Studio. It used to be that you needed
to install a Java Development Kit prior to installing Android Studio; starting from
Android Studio 2.2, the installer includes an embedded OpenJDK—you no longer need
to bother with installing a separate JDK.
Download the installer from https://developer.android.com/studio/, and get the
proper binary file for your platform.
If you’re on macOS, do the following:
Android Studio will prompt you to import some settings if you have a previous
installation. You can import that—it’s the default option.
8
CHAPTER 2 ANDROID STUDIO
Note If you have an existing installation of Android Studio, you can keep using
that version and still install the preview edition. Android Studio 4 can coexist
with your existing version of Android Studio; its settings will be kept in a different
directory.
The Linux installation requires a bit more work than simply double-clicking and
following the installer prompts. In future releases of Ubuntu (and its derivatives),
this might change and become as simple and frictionless as its Windows and macOS
counterparts, but for now, we need to do some tweaking. The extra activities on Linux
are mostly because AS needs some 32-bit libraries and hardware acceleration.
Note The installation instructions in this section are meant for Ubuntu 64-bit and
other Ubuntu derivatives, for example, Linux Mint, Lubuntu, Xubuntu, Ubuntu MATE,
and so on. I chose this distribution because I assumed that it is a very common
Linux flavor; hence, the readers of this book will be using that distribution. If you
are running a 64-bit version of Ubuntu, you will need to pull some 32-bit libraries
in order for AS to function well.
9
CHAPTER 2 ANDROID STUDIO
To start pulling the 32-bit libraries for Linux, run the following commands on a
terminal window:
When all the prep work is done, you need to do the following:
1. Unpack the downloaded installer file. You can unpack the file
using command-line tools or using the GUI tools—you can, for
example, right-click the file and select the “Unpack here” option, if
your file manager has that.
3. Move the folder to a location where you have read, write, and
execute privileges. Alternatively, you can also move it to /usr/
local/AndroidStudio.
5. At first launch, Android Studio will ask you if you want to import
some settings; if you have installed a previous version of Android
Studio, you may want to import those settings.
Launch Android Studio and click “Configure” (as shown in Figure 2-1), then choose
“Preferences” from the drop-down list.
10
CHAPTER 2 ANDROID STUDIO
The “Preferences” option opens the Preferences dialog. On the left-hand side, go to
Appearance & Behavior ➤ System Settings ➤ Android SDK, as shown in Figure 2-2.
11
CHAPTER 2 ANDROID STUDIO
When you get to the SDK window, enable the "Show Package Details" option so you
can see a more detailed view of each API level. We don’t need to download everything in
the SDK window. We will get only the items we need.
SDK levels or platform numbers are specific versions of Android. Android 10 is
API level 29, Android 9 or “Pie” is API level 28, Android 8 or “Oreo” is API levels 26
and 27, and Nougat is API levels 24 and 25. You don’t need to memorize the platform
numbers, at least not anymore because the IDE shows the platform number with the
corresponding Android nickname.
Download the API levels you want to target for your applications, but for the purpose
of this book, please download API level 29 (Android 10). That’s what we will use for the
sample projects. Make sure that together with the platforms, you will also download
"Google APIs Intel x86 Atom_64 System Image." We will need those when we get to the
part where we test run our applications.
Choosing an API level may not be a big deal right now because at this point, we’re
simply working with practice apps. When you plan to release your application to the
public, you may not be able to take this choice lightly. Choosing a minimum SDK or API
level for your app will determine how many people will be able to use your application.
At the time of writing, 17% of all Android devices are using “Marshmallow,” 19% for
“Nougat,” 29% for “Oreo,” and only 10% for “Pie”; the stats for Android 10 were not
12
CHAPTER 2 ANDROID STUDIO
out yet. These stats are from the dashboard page of the official Android website. It’s a
good idea to check these statistics from time to time; you can find it here: http://bit.ly/
droiddashboard.
We go next to the “SDK Tools” section, as shown in Figure 2-3.
You don’t generally have to change anything on this window, but it wouldn’t hurt to
check if you have the tools, as shown in the following list, marked as “Installed”:
13
CHAPTER 2 ANDROID STUDIO
• Android Emulator
• Support Repository
• HAXM Installer
Note If you are on the Linux platform, you cannot use HAXM even if you have an
Intel processor. KVM will be used in Linux instead of HAXM.
Once you’re happy with your selection, click the “OK” button to start downloading
the packages.
Hardware Acceleration
As you create applications, it will be useful to test and run it sometimes in order to get
immediate feedback and find out if it is running as expected or if it is running at all. To
do this, you will use either a physical or a virtual device. Each option has its pros and
cons, and you don’t have to choose one over the other; in fact, you will have to use both
options eventually.
An Android Virtual Device or AVD is an emulator where you can run your apps.
Running on an emulator can sometimes be slow; this is the reason why Google and Intel
came up with HAXM. It is an emulator acceleration tool that makes testing your app a bit
more bearable. This is definitely a boon to developers. That is if you are using a machine
that has an Intel processor which supports virtualization and that you are not on Linux.
But don’t worry if you’re not lucky enough to fall on that part of the pie, there are ways to
achieve emulator acceleration in Linux, as we’ll see later.
macOS users probably have it the easiest because HAXM is automatically installed
with Android Studio. They don’t have to do anything to get it; the installer took care of
that for them.
Windows users can get HAXM either by
• Alternatively, you can get HAXM via the SDK manager; this is the
recommended method.
14
Another Random Scribd Document
with Unrelated Content
ylleen ottanut; ryhdissä ja eleissä ilmeni sama varmuus kuin
kasvoissakin. Samaa soi äänikin, vaikka kyllä naisen sointisävyllä.
KAPINA JÖNKÖPINGISSÄ.
*****
Jönköpingin tori täyteen ahdettuna ihmisiä. Lähinnä raatihuoneen
portaita viisi kuusi haarniskoitua ratsumiestä, kypäreillään
sulkatöyhdöt tai muita merkkejä. Ne ovat vapaasukuisia
Länsigöötanmaalta, valtiohovimestarin Tuure Jönsinpojan ystäviä. Ja
heidän seurassaan on nuori herra Arvi Niilonpoika, joka
aamunkoitossa oli ratsain ajanut kaupunkiin niiden talonpoikain
etupäässä, jotka olivat linnaa rynnäköimässä.
*****
*****
— Ikuinen kiitos!
— Ei kannata kiittää.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com