[Android] submit data to the server in get mode

The content of this section is basically the same as that of the previous section, that is, splicing parameters on the URL, which is basically the same as others.

Interface layout, linear layout, EditText user name, EditText password, button button

In order to use this code to demonstrate various ways to request the server, create a new service package, a loginservice class to handle login requests, and a static method to return string type, loginbyget(), with user name and password as parameters

Assemble the string path, get the URL object, get the httpurlconnection object, and return the data after reading the data

Open the sub thread in the activity, rewrite the run method, call the service, and get the return data.

It's too troublesome to often use handler. Android provides an API to handle this situation. Call the runonuithread (action) method of the activity object and call the sub thread to the main thread for execution. Parameters: runable object. Runable class is an interface type. To implement this interface in an anonymous internal way, you must implement the run () method.

activity:

service:

Server side:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>