Book Image

Android High Performance Programming

By : Emil Atanasov, Enrique López Mañas, Diego Grancini
Book Image

Android High Performance Programming

By: Emil Atanasov, Enrique López Mañas, Diego Grancini

Overview of this book

Performant applications are one of the key drivers of success in the mobile world. Users may abandon an app if it runs slowly. Learning how to build applications that balance speed and performance with functionality and UX can be a challenge; however, it's now more important than ever to get that balance right. Android High Performance will start you thinking about how to wring the most from any hardware your app is installed on, so you can increase your reach and engagement. The book begins by providing an introduction to state–of-the-art Android techniques and the importance of performance in an Android application. Then, we will explain the Android SDK tools regularly used to debug and profile Android applications. We will also learn about some advanced topics such as building layouts, multithreading, networking, and security. Battery life is one of the biggest bottlenecks in applications; and this book will show typical examples of code that exhausts battery life, how to prevent this, and how to measure battery consumption from an application in every kind of situation to ensure your apps don’t drain more than they should. This book explains techniques for building optimized and efficient systems that do not drain the battery, cause memory leaks, or slow down with time.
Table of Contents (17 chapters)
Android High Performance Programming
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

Preface

Performant applications are one of the key drivers of success in the mobile world. Users may abandon an app if it runs slowly. Learning how to build applications that balance speed and performance with functionality and UX can be a challenge; however, it's now more important than ever to get that balance right.

Android High Performance Programming will make you think about how to wring the most from any hardware your app is installed on, so you can increase your reach and engagement. The book begins by providing an introduction to state-of-the-art Android techniques and the importance of performance in an Android application. Then, we will explain the Android SDK tools regularly used to debug and profile Android applications. We will also learn about some advanced topics such as building layouts, multithreading, networking, and security. Battery life is one of the biggest bottlenecks in applications; this book will show typical examples of code that exhausts battery life, how to prevent this, and how to measure battery consumption from an application in every kind of situation.

This book explains techniques for building optimized and efficient systems that do not drain the battery, cause memory leaks, or slow down with time.

What this book covers

Chapter 1, Introduction: Why High Performance?, provides an introduction to the topic, the current state of the art in Android, and the importance of performance in an Android application.

Chapter 2, Efficient Debugging, covers the tools provided by the Android SDK (and some externals) that are regularly used to debug and profile Android applications.

Chapter 3, Building Layouts, will take you through the techniques used to optimize Android routines, write applications that use memory efficiently, and explain concepts from memory allocation to garbage collection.

Chapter 4, Memory, provides many insights to the UI design that need to be learnt in order to create an efficient UI that loads fast, without giving a lag perception to the user and that gets updated efficiently.

Chapter 5, Multithreading, explains all the different threading options in an Android application and when we should apply each. Some advanced techniques, such as IPC, will be also shown with practical code.

Chapter 6, Networking, shows techniques used to perform efficient network operations, and techniques to retrieve data from servers such as exponential back offs or avoiding polling.

Chapter 7, Security, covers techniques to secure an Android application, how to make use of the security encryption mechanisms provided by Android natively, and how to get information about connections or just be notified of connection changes.

Chapter 8, Optimizing Battery Consumption, provides typical examples of code that exhausts battery life, how to prevent it, and how to measure battery consumption from an application in every kind of situation; many developers don't know how to behave while developing apps to take a photo or a video, handling with previews, and saving data.

Chapter 9, Native Coding in Android, this chapter is a workaround in the world of native code and C++ in Android and its usage.

Chapter 10, Performance Tips, helps developer to be guided in common coding situations, where wrong choices can compromise app efficiency; this will be a best practice guide related to topics not dealt with in previous chapters.

What you need for this book

You will need the following hardware for this book:

  • PC/laptop running Windows, Linux, or Mac OS X

  • Android phone. A high-end model is recommended, with at least Android 5.0 installed.

Who this book is for

This topic is aimed at developers with advanced knowledge of Android, who want to push their knowledge and learn techniques to increase the performance of their applications. We assume they are comfortable working with the entire Android SDK, and have been doing it for years. They are familiar also with frameworks such as the NDK to use native code, which is crucial to performance.

Conventions

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: "If you go to this folder and call the command adb, you will see on the screen a list of the available options."

A block of code is set as follows:

<resources>
    <style name="Theme.NoBackground" parent="android:Theme">
      <item name="android:windowBackground">@null</item>
    </style>
</resources>

Any command-line input or output is written as follows:

adb shell dumbsys gfxinfo <PACKAGE_NAME>

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: "To debug the overdraw on the device, Android provides a helpful tool that can be enabled inside the Developer options."

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 disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in 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 at 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 this book 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.

You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.

  2. Hover the mouse pointer on the SUPPORT tab at the top.

  3. Click on Code Downloads & Errata.

  4. Enter the name of the book in the Search box.

  5. Select the book for which you're looking to download the code files.

  6. Choose from the drop-down menu where you purchased this book from.

  7. Click on Code Download.

You can also download the code files by clicking on the Code Files button on the book's webpage at the Packt Publishing website. This page can be accessed by entering the book's name in the Search box. Please note that you need to be logged in to your Packt account.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows

  • Zipeg / iZip / UnRarX for Mac

  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Android-High-Performance-Programming. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

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 http://www.packtpub.com/sites/default/files/downloads/AndroidHighPerformanceProgramming_ColorImages.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 could 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 to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted 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

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.