Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Networking on a Mobile Device:
- When writing apps that involve any sort of networking code, we do need to keep the following points in mind.
- Networking rules to go by:
- -Transfer only as much data as needed // So its not slow, it costs users time, data usage money, and battery
- -avoid network timeouts //Mobile connections can be slower, and you don't want something to stop loading just because it took too long.
- -allow users to cancel network operations // ie: let users pause download
- -Handle Failures gracefully // Networks can suddenly fail, need to account for these situations. And let our apps, continue working as much as possible.
- -Keep User's security in mind
- // https://teamtreehouse.com/library/build-a-weather-app/networking/networking-on-a-mobile-device
- //
- Threads. Simple.
- Threads are like lanes on the highway.
- Main Thread is used for user interface
- we run the networking stuff on another thread (lane) in the background and update it to the main thread when we are done.
- ^this is asynchronous
- Concurrency - having multiple things happening at the same time.
- Concurrency improves the responsiveness of our code by insuring that the main thread ui is responding to the users and not waiting for the network to finish.
- We were using synchronous data when we left off OkHttp which is why their was an error: NetworkOnMainThread Exception
- // https://teamtreehouse.com/library/build-a-weather-app/concurrency-and-error-handling/why-do-we-use-asynchronous-processing
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement