Android Async Programming and Services

Learn how to provide a more responsive user experience in your Android applications through Android services and asynchronous processing.
Course info
Rating
(190)
Level
Advanced
Updated
Aug 22, 2011
Duration
3h 3m
Table of contents
Description
Course info
Rating
(190)
Level
Advanced
Updated
Aug 22, 2011
Duration
3h 3m
Description

In this course you will learn how to use Android services and asynchronous processing to create applications that provide a more responsive user experience. Topics covered include Android Services, background processing, threading, asynchronous tasks, Started Services, Foreground Services, Notifications, Android Service lifecycle, and ExecutorService.

About the author
About the author

Jim Wilson is president of JW Hedgehog, Inc., a consulting firm specializing in solutions for the Android, iOS, and Microsoft platforms. Jim has over 30 years of software engineering experience, with the past 15 years heavily focused on creating mobile device and location-based solutions.

More from the author
More courses by Jim Wilson
Section Introduction Transcripts
Section Introduction Transcripts

Implementing long-running operations as a service
Welcome to this module of implementing long-running operations as a service, my name is Jim Wilson. This module, we're going to take a first look at what a service is on the Android platform, how do we implement a service, and how do we utilize that service from other parts of our applications. Alright so let's take a look at the topics we're going to talk about in this module. First off, we're going to look at long-running operations. What does it mean to be a long-running operation and what are the effects on our applications when something runs as a long-running operation. We're then going to take our first look at Android services understand what they are, what their purpose is, how do we work with them. We're then going to look at something called an on-demand service basically the simplest kind of service we can implement and then we'll look at how we actually utilize that service. And then finally we'll look at the issues of trying to utilize a service across processes, if a service implemented one process and how components of other processes take advantage of that service.

Service lifecycle management
Welcome to this module on service lifecycle management. My name is Jim Wilson. In this module, we're going to take a look at the lifecycle of services, how things work for them from the time they start up until they terminate, and then, what are the capabilities that we have to actually control that behavior? All right, so first thing we're going to take a look at is the lifecycle itself. What is the lifecycle of a service? What are the aspects of it or stages of that lifecycle? And what are the hooks that we have to actually affect that process? When we create a service, what are the considerations with threads? We've talked about before with the on demand threads, excuse me. With the on demand service we implemented previously, we didn't really deal with threading because a lot of that was taken care of for us. We'll see that as we look at services more closely and all the capabilities that they have, there are some very important threading considerations that we are responsible for. Then we take a look at, how do we take a very direct control over the service lifetime? How do we actually allow our services to live on the terms that we choose, not just on the terms of how they're actually consumed by any individual user? And finally, what can we do with the operating system? How can we give the operating system hints about the way our service is used so that the operating system can help us out so that if the service is killed for some reason we can get the system automatically restarted for us? And some other issues.

Interacting with services
Welcome to this module on interacting with services, my name is Jim Wilson. In this module we're going to take a look at the environment the services run in and what are the capabilities that we have for services to interact with that environment. Right now the first thing we're going to look at is just kind of what's the need for service interaction? Kind of what are the things that kind of justify and kind of why does it matter? As we look at that environment one of the things that are important are of course providing user feedback. So what are the options we have there? A special state that a service can run in called a foreground service that changes its priority in terms of how it's treated by the system, but also opens it up to some greater user interaction capabilities. And finally, how those services actually interact with and become informed about system activity. Now a key thing for us to remember is that services don't exist in a vacuum. Services need to interact with many aspects of the environment around them. One thing that you obviously would expect is that services very often need to provide some kind of feedback to the user. If they don't necessarily have a user interface, but you still want to keep the user informed of certain activities that may go on. Depending on the state of the service and what it's doing you may want to also provide an opportunity for the user to act somehow. In the sense that you might want to let them know that something has happened and make it easy for them to jump to a screen or do something in response to that activity. And of course the service itself is running on the device. The device goes through changes, it gets rebooted, it has power state changes. All those things can be important to your service and your service needs a way to respond to those that behave correctly.