Book Image

Android Studio Cookbook

By : Mike van Drongelen
Book Image

Android Studio Cookbook

By: Mike van Drongelen

Overview of this book

This book starts with an introduction of Android Studio and why you should use this IDE rather than Eclipse. Moving ahead, it teaches you to build a simple app that requires no backend setup but uses Google Cloud or Parse instead. After that, you will learn how to create an Android app that can send and receive text and images using Google Cloud or Parse as a backend. It explains the concepts of Material design and how to apply them to an Android app. Also, it shows you how to build an app that runs on an Android wear device. Later, it explains how to build an app that takes advantage of the latest Android SDK while still supporting older Android versions. It also demonstrates how the performance of an app can be improved and how memory management tools that come with the Android Studio IDE can help you achieve this. By the end of the book, you will be able to develop high quality apps with a minimum amount of effort using the Android Studio IDE.
Table of Contents (17 chapters)
Android Studio Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Android Studio is the best IDE for developing Android apps, and it is available for free to anyone who wants to develop professional Android apps.

Now with Android Studio, we have a stable and faster IDE, and it comes with a lot of cool stuff such as Gradle, better refactoring methods, and a much better layout editor. If you have used Eclipse, then you will love this IDE.

In short, Android Studio has really brought back the fun of mobile development, and in this book, we will see how.

What this book covers

Chapter 1, Welcome to Android Studio, demonstrates how to configure Android Studio and Genymotion, which is a really fast emulator.

Chapter 2, Applications with a Cloud-based Backend, explains how to use Parse to develop an app using a cloud-based backend in no time.

Chapter 3, Material Design, explains the concept of material design and how to implement it using RecycleViews, CardViews, and transitions.

Chapter 4, Android Wear, covers the Android Wear API and how to develop your own watch face or other apps running on a smart watch.

Chapter 5, Size Does Matter, demonstrates how using fragments and additional resources can help you to create an app that is able to run on a phone, phablet, tablet, or even on TV. On the fly, we will connect to the YouTube API to make the recipes more fun.

Chapter 6, Capture and Share, is an in-depth tutorial about capturing and previewing images using the new Camera2 API, in particular. It also tells you how to share a captured image on Facebook.

Chapter 7, Content Providers and Observers, explains how you can benefit from using content providers to display and observe persisting data.

Chapter 8, Improving Quality, elaborates on applying patterns, unit testing, and code analysis tools.

Chapter 9, Improving Performance, covers how the Device Monitor can be used to optimize your apps' memory management and how the developer options on your phone can be used to detect overdraw and other performance issues.

Chapter 10, Beta Testing Your Apps, guides you through some of the final steps such as using build variants (types and flavors) and beta distribution on the Google Play Store. In addition to this, it covers how the run time permissions that come with Android Marshmallow (6.0) differ from the install permissions.

What you need for this book

For this book, you need to download and set up Android Studio and the latest SDKs. Android Studio is free and is available for Windows, OSX, and Linux.

Having at least one phone, phablet, or tablet is strongly recommended, but in Chapter 1, Welcome to Android Studio we will introduce you to Genymotion, a really fast emulator, which you can use instead of a real device in most cases.

Finally, for some recipes, you need to have a Google developer account. If you do not have one yet, I suggest that you get one as soon as possible. After all, you will need one in order to be able to get your app into the Play Store.

Who this book is for

This book is for anyone who is already familiar with the Java syntax and perhaps has already developed some Android apps, for example, using the Eclipse IDE.

This book explains the concepts of Android development using Android Studio in particular. To demonstrate these concepts, real-world recipes are provided. And, by real-world apps, I mean apps that do connect to a backend and communicate with Google Play services or Facebook and so on.

Sections

In this book, you will find several headings that appear frequently (Getting ready, How to do it, How it works, There's more, and See also).

To give clear instructions on how to complete a recipe, we use these sections as follows:

Getting ready

This section tells you what to expect in the recipe, and describes how to set up any software or any preliminary settings required for the recipe.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There's more…

This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.

See also

This section provides helpful links to other useful information for the recipe.

Conventions

All screenshots, shortcuts and other elements that are specific for Android Studio are based on Android Studio for OSX.

The main reason that OSX is being used is because it allows us to develop apps for both Android and iOS on the same machine. Other than that there is no reason to choose a particular OS other than your personal (or companies) preferences.

While the screenshots are based on Android Studio for OSX it is not too difficult for you to figure things out in case your OS is Windows or Linux.

Where needed the short cuts for Windows are mentioned as well.

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We can include other contexts through the use of the include directive."

A block of code is set as follows:

public void onSectionAttached(int number) {
    switch (number) {
        case 0:
            mTitle = getString(  
             R.string.title_section_daily_notes);
            break;

        case 1:
            mTitle = getString( 
             R.string.title_section_note_list);
             break;
    }
}

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Clicking the Next button moves you to the next screen."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/B04299_ColoredImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.