Before I get to working with web services, I'll describe how to use the AsyncTask class to manage background threads in an Android app. I'm working in the project AsyncTask and I'll start in the main activity class. To work with AsyncTask, you create a subclass of AsyncTask. And typically you declare this subclass as an member class of the activity that's going to use the background thread.
- Before I get to working with web services, I'll describe…how to use the AsyncTask class to manage background threads…in an Android app. I'm working in the project AsyncTask.…Now this isn't the full Nadia's Restaurant application,…it's a much simpler application. It's designed to let me…experiment with code in a very isolated application.…I'm running it on a Nexus 5X and each time I click the…RUN CODE button at the bottom, I'm getting output.…A simple string of "button clicked", and when I press the…clear button, the output is cleared.…
This application is designed so I can run some simple…code in the runcClickHandler method and see…exactly what that code does. To work with AsyncTask,…you subclass it and typically you declare your extension…of the class as a member class of the activity that's…going to use the background thread.…So I'll place the cursor down here, still within the…class declaration but outside of any methods,…and I'll declare a new private class.…And I'll name it MyAsyncTask…and I'll say that it extends AsyncTask.…
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