ebook img

Efficient Android Threading Asynchronous Processing Techniques for Android Applications PDF

353 Pages·2014·4.95 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Efficient Android Threading Asynchronous Processing Techniques for Android Applications

Efficient Android Threading Anders Göransson Dedication To Anna, Fabian, and Ida. Preface Efficient Android Threading explores how to achieve robust and reliable multithreaded Android applications. We’ll look at the asynchronous mechanisms that are available in the Android SDK and determine appropriate implementations to achieve fast, responsive, and well-structured applications. Let’s face it: multithreading is required to create applications with a great user experience, but it also increases the complexity of the application and the likelihood of runtime errors. The complexity partly comes from the built-in difficulty of execution on multiple threads and from applications that aren’t utilizing the Android platform efficiently. This book aims to guide application developers to selecting an asynchronous mechanism based on an understanding of its advantages and difficulties. By using the right asynchronous mechanism at the right time, much of the complexity is transferred from the application to the platform, making the application code more maintainable and less error prone. As a rule of thumb, asynchronous execution should not induce more complexity to the code than necessary, which is achieved through a wise choice from the palette of asynchronous mechanisms in Android. Although a high-level asynchronous mechanism can be very convenient to use, it still needs to be understood — not only used — or the application may suffer from equally difficult runtime errors, performance degradation, or memory leaks. Therefore, this book not only contains practical guidelines and examples, but also explores the underlying enablers for asynchronous execution on Android. Audience This book is for Java programmers who have learned the basics of Android programming. The book introduces techniques that are fundamental to writing robust and responsive applications, using standard Android libraries. Contents of This Book This book contains two main parts: Part I and Part II. The first part describes the foundation for threads on Android — i.e., Java, Linux, Handlers — and its impact on the application. The second part is more hands-on, looking into the asynchronous mechanisms that an application has at its disposal. Part I describes how Java handles threads. As an Android programmer, you will sometimes use these libraries directly, and understanding their behavior is important for using the higher-level constructs in Part II correctly. Chapter 1 Explains how the structure of the Android runtime and how the various components of an Android application affect the use of threads and multiprocessing. Chapter 2 Covers the fundamentals of concurrent execution in Java. Chapter 3 Describes how Android handles threads and how the application threads execute in the Linux OS. It includes important topics like scheduling and control groups, as well as their impact on responsiveness. Chapter 4 Covers basic communication between threads, such as shared memory, signals, and the commonly used Android messages. Chapter 5 Shows how Android enhances the IPC mechanisms in Linux with mechanisms such as RPC and messaging. Chapter 6 Explains how to avoid leaks, which can cause apps to degrade the system and be uninstalled by users. Part II covers the higher-level libraries and constructs in Android that make programming with threads safer and easier. Chapter 7 Describes the most basic asynchronous construction, i.e, java.lang.Thread, and how to handle the various states and problems that can occur. Chapter 8 Shows a convenient way to run tasks sequentially in the background. Chapter 9 Offers techniques for dealing with scheduling, errors, and other aspects of thread handling, such as thread pools. Chapter 10 Covers the AsyncTask — probably the most popular asynchronous technique — and how to use it correctly to avoid its pitfalls. Chapter 11 Covers the essential Service component, which is useful for functionality that you want to offer to multiple applications or to keep the application alive during background execution. Chapter 12 Builds on the previous chapter with a discussion of a useful technique for executing off the main UI thread. Chapter 13 A high-level mechanism that simplifies fast asynchronous access to content providers. Chapter 14 Discover how the UI can be updated with loaders, where new data is delivered asynchronously whenever the content changes. Chapter 15 Given all the techniques described throughout this book, how do you choose the right one for your app? This chapter offers guidelines for making this choice. Conventions Used in this Book The following typographical conventions are used in this book: Italic Used for emphasis, new terms, URLs, commands and utilities, and file and directory names. Constant width Indicates variables, functions, types, objects, and other programming constructs. Constant width italic Indicates place-holders in code or commands that should be replaced by appropriate values. TIP This element signifies a tip, suggestion, or a general note. CAUTION This element indicates a trap or pitfall to watch out for, typically something that isn’t immediately obvious. Using Code Examples Supplemental material (code examples, exercises, etc.) is available for download at https://github.com/andersgoransson/eatbookexamples. This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you are reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission. We appreciate attribution. An attribution usually includes the title, author, publisher, and ISBN. If you believe that your use of code examples falls outside of fair use or the permission given above, feel free to contact us at [email protected]. Examples will be maintained at: [email protected]:andersgoransson/eatbookexamples.git Safari® Books Online NOTE Safari Books Online is an on-demand digital library that delivers expert content in both book and video form from the world’s leading authors in technology and business. Technology professionals, software developers, web designers, and business and creative professionals use Safari Books Online as their primary resource for research, problem solving, learning, and certification training. Safari Books Online offers a range of product mixes and pricing programs for organizations, government agencies, and individuals. Subscribers have access to thousands of books, training videos, and prepublication manuscripts in one fully searchable database from publishers like O’Reilly Media, Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que, Peachpit Press, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, Course Technology, and dozens more. For more information about Safari Books Online, please visit us online.

Description:
Multithreading is essential if you want to create an Android app with a great user experience, but how do you know which techniques can help solve your problem? This practical book describes many asynchronous mechanisms available in the Android SDK, and provides guidelines for selecting the ones mos
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.