Preface

Programming is the most fun a person can have on their own. This is a fact well-known to programmers, though it seems the rest of the world is yet to catch on. You already know this or you wouldn't be reading this book, but it constantly amazes me that more people aren't falling over themselves to learn to code.

Meanwhile, mobile devices have made computers fun even for non-coders. We carry in our pockets small machines with incredible processing power and a giddying array of sensors and interfaces.

Android takes these fun machines and makes them accessible to programmers through a fabulously well-crafted platform and tool chain, in a programming language that has stood the test of time yet continues to develop and evolve.

What could possibly be better than programming fun machines to do cool things, in a powerful language, on a well-crafted platform, with a world-class tool chain? For me, the answer is doing so with a good enough understanding of those things to make the difference between a good app and a great one.

There are many things that must come together to make a great app. You need a great idea—I can't help you there. You need a pretty user interface—sorry, wrong book. You need a great user experience—aha! Now we're getting somewhere. Among the many things that contribute to a great user experience, responsiveness is right up there near the top of the list.

It's easiest to define responsiveness with examples of its lack: pauses and glitches while scrolling content, user interfaces that freeze while loading data from storage, applications that don't give progress updates to let us know what's happening, failing to complete work that we initiated, staring at a spinner while data is fetched from the network, and the list goes on.

This book is about making the difference between a good app and a great one; smoothing out the glitches, keeping the UI responsive, telling the user how things are going, making sure we finish what we started, using those powerful multicore processors, and doing it all without wasting the battery. Let's have some fun!

What this book covers

Chapter 1, Building Responsive Android Applications, gives an overview of the Android process and thread model, and describes some of the challenges and benefits of concurrency in general, before discussing issues specific to Android.

Chapter 2, Staying Responsive with AsyncTask, covers the poster child of concurrent programming in Android. We learn how AsyncTask works, how to use it correctly, and how to avoid the common pitfalls that catch out even experienced developers.

Chapter 3, Distributing Work with Handler and HandlerThread, details the fundamental and related topics of Handler, HandlerThread, and Looper, and illustrates how they can be used to schedule tasks on the main thread, and to coordinate and communicate work between cooperating background threads.

Chapter 4, Asynchronous I/O with Loader, introduces the Loader framework and tackles the important task of loading data asynchronously to keep the user interface responsive and glitch free.

Chapter 5, Queuing Work with IntentService, gives us the means to perform background operations beyond the scope of a single Activity lifecycle and to ensure that our work is completed even if the user leaves the application.

Chapter 6, Long-running Tasks with Service, extends the capabilities we discovered with IntentService and gives us control over the level of concurrency applied to our long-running background tasks.

Chapter 7, Scheduling Work with AlarmManager, completes our toolkit by enabling us to arrange for work to be done far into the future and on repeating schedules. It also enables us to build apps that alert users to new content and start instantly with fresh data.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.249.59