且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android 侦听来自服务器套接字的消息

更新时间:2023-11-07 20:36:22

您可以在您的 Service 中创建一个线程来监听服务器.第二个线程用于发送命令.然后对于您的服务,您应该创建一个带有处理程序的主线程.此处理程序将处理来自这两个线程的消息.

You can create in your Service one thread for listening to the server. The second thread is for sending commands. Then for your service you should create a main thread with handler in it. This handler will process messages from this two threads.