To communicate from an IntentService back to the user interface, you can use broadcast messages. There are a couple of kinds of broadcast messages. The ones you want to use are called local messages, since they stay within a single app’s process and aren’t available to other apps on the device. You’ll use a class named LocalBroadcastManager that’s included in the support repository to send messages, and a BroadcastReceiver to receive and handle messages.
- To communicate from an intent service…back to the user interface,…you can use broadcast messages.…There are a couple of different kinds…of broadcast messages in Android.…The type you want to use here…are called local messages.…Since they stay within a single app's process…and aren't available to other apps on the device.…You'll use a class named Local Broadcast Manager…that's included in the support respository…to send the messages, and a broadcast receiver…to receive and handle the messages.…First, send a message from the service.…
You'll need a couple of constants;…one to identify the message,…and another to identify what we'll call the message payload.…You can define the constants right here in the service,…or create your own helper class to define them.…I'll put them in the service, and I'll make them public…so they can be accessed from anywhere in the application.…I'll start here, and I'll use the PSF code template;…that expands to public static final.…And I'll create a string that I'll name My Service Message;…
IInstructor David Gassner starts with an overview discussion about available networking strategies, and then dives into how to declare networking permissions, make network requests, handle responses, parse data returned from a web service, and pass user credentials to services that support HTTP basic authentication. He also provides an overview of popular higher-level networking libraries, including OkHttp and Picasso, and offers recommendations for improving performance in network-connected apps. David also covers using static feeds, using dynamic PHP pages hosted on a public server web service, and integrating apps with network data storage.
- Integrating mobile apps
- Communicating with Android
- Preventing app freezes with background threads
- Preparing an app for network communication
- Declaring permissions
- Checking network connectivity
- Retrieving data over the web
- Using traditional APIs
- Using third-party libraries