Android realizes login function through PHP server

Android client and PHP, @ r_ 419_ 1638 @ build a simple interaction between servers to realize the login function.

Implementation schematic diagram:

Principle of handler message mechanism:

The handler mechanism mainly includes four key objects: message, handler, messagequeue and looper.

These four key objects are briefly introduced below.

1.Message

Message is a message passed between threads. It can carry a small amount of information internally for exchanging data between different threads. The what field of message can be used to carry some integer data, and the obj field can carry an object object.

2.Handler

Handler means handler. It is mainly used to send and process messages. Generally, the SendMessage () method of the handler object is used to send messages. After a series of twists and turns, the sent messages will eventually be delivered to the handlermessage () method of the handler object.

3.MessageQueue

Messagequeue means message queue. It is mainly used to store messages sent through the handler. Messages sent through the handler will be stored in the messagequeue for processing. There will only be one messagequeue object per thread.

4.Looper

Looper is the steward of the messagequeue in each thread. After calling Looper's loop () method, you enter an infinite loop. Then, whenever a message is found in the messagequeue, it is taken out and passed to the handler's handlermessage () method. In addition, each thread will have only one looper object. When creating the handler object in the main thread, the system has already created the loop object, so you do not need to create the loop object manually. For the handler object in the sub thread, you need to call the loop. Loop () method to start the message loop.

You can clearly see the whole handler message mechanism processing flow in the figure. Handler message processing first needs to create a Handler object in the UI thread, and then invokes the sendMessage () method in the sub thread. Then the message will be stored in the MessageQueue of the UI thread, and the message in MessageQueue will be removed through the Looper object, and finally sent back to the HandMessage () method of Handler.

The following is the code I wrote and the running result of logcat of this program.

Difficulties encountered in this task:

Unable to connect to PHP server. The user name and password you entered are encapsulated into JSON, but they cannot be sent to PHP for comparison with the database.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

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
分享
二维码
< <上一篇
下一篇>>