A little bit of attention to Android and server communication

Source: Internet
Author: User
Nearly two days in the study of how the Android client communicates with the server, looked up the data to see a lot of blogs, found that although it may not be difficult to achieve, but there are many small details to be aware of. The first is the environment and the need for the construction of the package, there are several points to note: Build the server first need to build a good environment, download good tomcat,jdk,eclipse after the correct configuration path. Accessing the database in a Java Web project requires downloading the appropriate database driver, which is similar to Java for the connection code. When you use JSON-related classes in your server, you also need to import the appropriate packages to work properly. In the process of writing code also found a lot of small problems, I summed up the following points: 1. Access network issues. 1>.android does not directly access the network in the main thread. Due to the time required to access the network, if the network is accessed directly in the main thread, the request fails to execute down and the timeout is very easy. Therefore, if you need to use a service that accesses the network, you need to open a new thread to perform the task of accessing the network. 2>: The newly-opened child thread needs to notify the mainline friend to perform the data update normally. Although Android is primarily Java-based development, it is still somewhat different from Java. When you create a new child thread, you need to establish a related class to connect the main thread to the child thread to update and get the data normally. 3>. When accessing the server you are building, pay attention to the access address I personally use the service side of Tomcat-based servers, when Android accesses the service side, The IP address in the access address is not writable. LocalHost in localhost.android represents not the host IP address, so the correct host IP address is written so that the server can be accessed normally. On the service side of the building, I am still groping. But the entire client side of the interaction as I understand the following: The client makes the request, service-side response request, service-side access to the database, and the server to data transfer in JSON format to client-side parsing data, The client displays the data in the app interface. When I get the data from the server, I can't access the servlet resource that transmits the data, but I can access the JSP interface which is written by the service side, this problem has not been solved, I will continue to look for the solution.

A little bit of attention to Android and server communication

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.