Advertisement
yo2man

Networking on a Mobile Device:

Jul 5th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.48 KB | None | 0 0
  1. Networking on a Mobile Device:
  2.  
  3. When writing apps that involve any sort of networking code, we do need to keep the following points in mind.
  4.  
  5.  
  6. Networking rules to go by:
  7. -Transfer only as much data as needed  // So its not slow, it costs users time, data usage money, and battery
  8. -avoid network timeouts //Mobile connections can be slower, and you don't want something to stop loading just because it took too long.
  9. -allow users to cancel network operations // ie: let users pause download
  10. -Handle Failures gracefully // Networks can suddenly fail, need to account for these situations. And let our apps, continue working as much as possible.
  11. -Keep User's security in mind
  12.  
  13. // https://teamtreehouse.com/library/build-a-weather-app/networking/networking-on-a-mobile-device
  14.  
  15.  
  16. //
  17.  
  18. Threads. Simple.
  19. Threads are like lanes on the highway.
  20.  
  21. Main Thread is used for user interface
  22. we run the networking stuff on another thread (lane) in the background and update it to the main thread when we are done.
  23. ^this is asynchronous
  24.  
  25. Concurrency - having multiple things happening at the same time.
  26. 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.
  27.  
  28. We were using synchronous data when we left off OkHttp which is why their was an error: NetworkOnMainThread Exception
  29.  
  30. // 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