【发布时间】:2011-06-22 00:08:36
【问题描述】:
我有一个监听传入消息的客户端软件(在 Android 上)。消息在等待消息到来的 while 循环中接收。找到消息后,它会更新 GUI。 [由于在 Android 中,无法直接更新 GUI ] 调用一个线程来执行此操作。我的问题是,如果有很多消息,会导致很多线程!它创造了一个笨拙的情况。我的抽象代码是,
My_Client()
{
send_text_function() // My question is not about it
in_a_thread_Call_receive_from_others_function() [see 1]
}
receiving_funtion() // [this function is mentioned above as (see 1), called in a thread]
{
while( waiting for new message)
{
>>A new message found >> create a thread to update the GUI. // << Here is my question. see 2
//android.os.Handler.thread type thread!
}
}
标签 2:现在每次有消息时都会创建此线程。我怎样才能只创建一个线程并一次又一次地使用它?有什么想法吗?
【问题讨论】:
标签: android multithreading user-interface