To make a good Android application, it is essential to use the network communication technology, it is difficult to imagine a software without network interaction can eventually develop much success. So let's take a look at how web interactions are implemented in general Android apps, and here's an example of a Boook object:
As shown above, first on the phone to generate a book object, which contains the title, author, price and other data. To send this data to the server side, we take the data out of the book object and assemble it into an XML-formatted string. Then through the network API, the assembled XML string is sent to the server side. The server receives the XML string sent from the client, and the XML is parsed. The parsed data is then reassembled into a book object, and the server can then perform a series of other operations on the object.
Of course the amount of data in the XML format is large, and now many Android apps are using JSON format to transfer data in order to save traffic. However, whether using XML or JSON, the steps described in the above diagram are always unavoidable.
Feeling that this is the way to transfer data, each time the process of encapsulating and parsing XML is the most cumbersome, can you bypass the most tedious process?
As shown in the figure above, if you can call the network API and send the book object directly to the server, the entire network interaction process becomes very simple, so let's look at how to implement it.