Asynchronous Android Programming - Second Edition

Unlock the power of multi-core mobile devices to build responsive and reactive Android applications

Asynchronous Android Programming - Second Edition

This ebook is included in a Mapt subscription
Helder Vasconcelos

2 customer reviews
Unlock the power of multi-core mobile devices to build responsive and reactive Android applications
$10.00
$49.99
RRP $39.99
RRP $49.99
eBook
Print + eBook
Preview in Mapt

Book Details

ISBN 139781785883248
Paperback394 pages

Book Description

Asynchronous programming has acquired immense importance in Android programming, especially when we want to make use of the number of independent processing units (cores) available on the most recent Android devices. With this guide in your hands you’ll be able to bring the power of Asynchronous programming to your own projects, and make your Android apps more powerful than ever before!

To start with, we will discuss the details of the Android Process model and the Java Low Level Concurrent Framework, delivered by Android SDK. We will also guide you through the high-level Android-specific constructs available on the SDK: Handler, AsyncTask, and Loader. Next, we will discuss the creation of IntentServices, Bound Services and External Services, which can run in the background even when the user is not interacting with it. You will also discover AlarmManager and JobScheduler APIs, which are used to schedule and defer work without sacrificing the battery life. In a more advanced phase, you will create background tasks that are able to execute CPU-intensive tasks in a native code-making use of the Android NDK. You will be then guided through the process of interacting with remote services asynchronously using the HTTP protocol or Google GCM Platform. Using the EventBus library, we will also show how to use the Publish-Subscribe software pattern to simplify communication between the different Android application components by decoupling the event producer from event consumer.

Finally, we will introduce RxJava, a popular asynchronous Java framework used to compose work in a concise and reactive way. Asynchronous Android will help you to build well-behaved applications with smooth responsive user interfaces that delight the users with speedy results and data that’s always fresh.

Table of Contents

Chapter 1: Asynchronous Programming in Android
Android software stack
Android process model
Android thread model
Concurrency in Android
Android primary building blocks
Service in a separate process
Summary
Chapter 2: Performing Work with Looper, Handler, and HandlerThread
Understanding Looper
Summary
Chapter 3: Exploring the AsyncTask
Introducing AsyncTask
Declaring AsyncTask types
Executing AsyncTasks
Providing indeterministic progress feedback
Providing deterministic progress feedback
Canceling an AsyncTask
Handling exceptions
Controlling the level of concurrency
Common AsyncTask issues
Applications of AsyncTask
Summary
Chapter 4: Exploring the Loader
Introducing Loaders
Loading data with Loader
Building responsive apps with AsyncTaskLoader
Building responsive apps with CursorLoader
Combining Loaders
Applications of Loader
Summary
Chapter 5: Interacting with Services
Introducing Service
Started service
Bound Service
Applications of Services
Summary
Chapter 6: Scheduling Work with AlarmManager
Introducing AlarmManager
Scheduling alarms with AlarmManager
Canceling alarms
Scheduling repeating alarms
Scheduling an alarm clock
Handling alarms
Handling alarms with Activities
Handling alarms with BroadcastReceiver
Handling alarms with Services
Resetting alarms after a system reboot
Applications of AlarmManager
Summary
Chapter 7: Exploring the JobScheduler API
Introduction to JobScheduler
Setting running criteria
Scheduling a job
Implementing the JobService
Listing pending jobs
Canceling a job
Scheduling a periodic job
Applications of the JobScheduler
Summary
Chapter 8: Interacting with the Network
Introducing Android HTTP clients
Performing HTTP requests asynchronously
Customizing HTTP timeouts
Communicating securely over SSL sessions
Summary
Chapter 9: Asynchronous Work on the Native Layer
Introduction to JNI
Calling C functions from Java code
Calling C++ functions from native code
Accessing Java objects from native code
Executing native background work on Java threads
Executing asynchronous work on a native thread
Handling Java exceptions in the native layer
Interacting with a Java monitor from native code
Summary
Chapter 10: Network Interactions with GCM
Introduction to GCM
Setting up and configuring GCM for your application
Receiving downstream messages
Receiving messages from topic
Sending upstream messages
GcmListenerService delivery callbacks
Executing tasks with GCM Network Manager
Summary
Chapter 11: Exploring Bus-based Communications
Introduction to bus-based communication
EventBus library
Defining events
Submitting events
Registering sbscribers
Thread mode
Posting sticking events
Removing sticky events
Summary
Chapter 12: Asynchronous Programing with RxJava
Introduction to RxJava
RxJava setup
Creating Observables
Transforming Observables
Understanding Schedulers
Performing IO operations with Schedulers
Canceling subscriptions
Composing Observables
Monitoring the event stream
Combining Observables
Observing UI Events with RxJava
Working with Subjects
Summary

What You Will Learn

  • Get familiar with the android process model and low-level concurrent constructs delivered by the Android SDK
  • Use AsyncTask and loader framework to load data in the background, delivering progress results in the meantime
  • Create services that interact with your activity without compromising the UI rendering
  • Learn the working of Android concurrency on the Native Layer
  • Interact with nearby devices over Bluetooth and WiFi communications channels
  • Create and compose tasks with RxJava to execute complex asynchronous work in a predictable way
  • Get accustomed to the use of the Android Loader construct to deliver up-to-date results

Authors

Table of Contents

Chapter 1: Asynchronous Programming in Android
Android software stack
Android process model
Android thread model
Concurrency in Android
Android primary building blocks
Service in a separate process
Summary
Chapter 2: Performing Work with Looper, Handler, and HandlerThread
Understanding Looper
Summary
Chapter 3: Exploring the AsyncTask
Introducing AsyncTask
Declaring AsyncTask types
Executing AsyncTasks
Providing indeterministic progress feedback
Providing deterministic progress feedback
Canceling an AsyncTask
Handling exceptions
Controlling the level of concurrency
Common AsyncTask issues
Applications of AsyncTask
Summary
Chapter 4: Exploring the Loader
Introducing Loaders
Loading data with Loader
Building responsive apps with AsyncTaskLoader
Building responsive apps with CursorLoader
Combining Loaders
Applications of Loader
Summary
Chapter 5: Interacting with Services
Introducing Service
Started service
Bound Service
Applications of Services
Summary
Chapter 6: Scheduling Work with AlarmManager
Introducing AlarmManager
Scheduling alarms with AlarmManager
Canceling alarms
Scheduling repeating alarms
Scheduling an alarm clock
Handling alarms
Handling alarms with Activities
Handling alarms with BroadcastReceiver
Handling alarms with Services
Resetting alarms after a system reboot
Applications of AlarmManager
Summary
Chapter 7: Exploring the JobScheduler API
Introduction to JobScheduler
Setting running criteria
Scheduling a job
Implementing the JobService
Listing pending jobs
Canceling a job
Scheduling a periodic job
Applications of the JobScheduler
Summary
Chapter 8: Interacting with the Network
Introducing Android HTTP clients
Performing HTTP requests asynchronously
Customizing HTTP timeouts
Communicating securely over SSL sessions
Summary
Chapter 9: Asynchronous Work on the Native Layer
Introduction to JNI
Calling C functions from Java code
Calling C++ functions from native code
Accessing Java objects from native code
Executing native background work on Java threads
Executing asynchronous work on a native thread
Handling Java exceptions in the native layer
Interacting with a Java monitor from native code
Summary
Chapter 10: Network Interactions with GCM
Introduction to GCM
Setting up and configuring GCM for your application
Receiving downstream messages
Receiving messages from topic
Sending upstream messages
GcmListenerService delivery callbacks
Executing tasks with GCM Network Manager
Summary
Chapter 11: Exploring Bus-based Communications
Introduction to bus-based communication
EventBus library
Defining events
Submitting events
Registering sbscribers
Thread mode
Posting sticking events
Removing sticky events
Summary
Chapter 12: Asynchronous Programing with RxJava
Introduction to RxJava
RxJava setup
Creating Observables
Transforming Observables
Understanding Schedulers
Performing IO operations with Schedulers
Canceling subscriptions
Composing Observables
Monitoring the event stream
Combining Observables
Observing UI Events with RxJava
Working with Subjects
Summary

Book Details

ISBN 139781785883248
Paperback394 pages
Read More
From 2 reviews

Read More Reviews