Before doing the Android project, HTTP requests are httpurlconnection and HttpClient in the Android API, the coding is cumbersome, and the package itself is not good. It was later known that there were a lot of Web requests for third-party frameworks that could be easily integrated into our projects, more stable and prescriptive than the Web requests we wrote. Among them, Okhttp was well received, so it took some time to understand and learn.
1. For okhttp use tutorial, please click.
2. The okhttp was encapsulated by the Hon Yang Great God, and the coding became more streamlined. Click here for details.
3, in reading the blog of the Great God, solve some confusing points of knowledge.
3.1. What is the difference between sychronized (Xxx.class) and sychronized (this)?
Synchronized (Threadtest.class) is the ThreadTest this class to lock, class inside the properties, methods are synchronous, the singleton mode is used in this way;
Synchronized (this) {} is a lock on the contents of {}, just for the current object.
3.2. What is Creator mode?
Time to use: when the system needs to create a complex object, and this complex object is more cumbersome to assemble, use the creator mode.
Please click here for details.
3.3, the callback function understanding.
My understanding of the callback function is this: Class A calls a method C (callback function) of Class B, and the logic in method C can be customized by a. Click here for details.
--okhttp Learning for Android Web request