Ch 7: Using Internet Resources Flashcards
Using Internet Resources:
Important Concepts
- Android Network APIs
- Creating Network Connections
- Performing Network operations on Background Threads
- Using View Model and Live Data
- Parsing Files
- Download Manager
- Best Practices: Energy Conservation
- Internet Services
Android Network APIs:
Kinds of tasks they allow you to accomplish
- Connect to remote server endpoints
- Make HTTP requests
- Process server results and data feeds
- Use parser to process data
Android Network APIs:
Two connection types available
Mobile Internet:
- GPRS, EDGE, 3G, 4G, LTE Internet access
Wi-Fi:
Private and Public Wi-Fi access points
Android Network Connections:
Basic Considerations when using Internet Resources
- Some connections will have very low bandwidth
- Wi-Fi connections may be unreliable:
- User might pass out of range
- Mobile connections can be costly to the user due to data charges
- Transmitting data drains power from the battery
- Quantity of data transmitted should be minimized
- App should be robust enough to handle:
- Network outages
- Bandwidth/Latency limitations
Benefits of a Native Internet Applications
vs
Web Apps accessed with Browser
- Less bandwidth required
- Only update things that change
- Offline Availability
- Lower Latency
- Better UX
- Consistent with OS
- Reduce battery drain
- using bundled connections
- Access to native features
Android Network APIs
Connecting to an Internet Resource:
Important Classes
- URL
- URLConnection
- HttpURLConnection
- InputStream
Android Network APIs
Two Major Packages for Networking
java. net
android. net
Android Network APIs
Connecting to an Internet Resource:
Basic Steps (HTTP Connection)
Add an INTERNET uses-permission node to the application manifest
Create a URL instance:
URL url = new URL(myFeed);
Open a connection, cast to connection type:
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
Check the response code of the connection:
httpConnection.getResponseCode();
Get an InputStream from connection:
InputStream in = conn.getInputStream();
When done, disconnect:
conn.disconnect();