Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何正确清洁未使用的线程?_Android_Multithreading_User Interface - Fatal编程技术网

Android 如何正确清洁未使用的线程?

Android 如何正确清洁未使用的线程?,android,multithreading,user-interface,Android,Multithreading,User Interface,我有一个客户端软件(在安卓系统上)可以监听传入的消息。消息在等待消息到来的while循环中接收。当发现消息时,它会更新GUI。[因为在Android中,GUI不能直接更新]调用线程来完成此操作。我的问题是,如果有很多消息,就会产生很多线程!这造成了一种笨拙的局面。我的抽象代码是 My_Client() { send_text_function() // My question is not about it in_a_thread_Call_receive_from_others_fun

我有一个客户端软件(在安卓系统上)可以监听传入的消息。消息在等待消息到来的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!
  } 
}
我的客户机()
{
send_text_function()//我的问题不是关于它的
在线程调用函数()中,从其他函数()接收函数[参见1]
}
receiving_function()/[此函数在上面提到为(参见1),在线程中调用]
{
while(等待新消息)
{
>>发现一条新消息>>创建一个线程以更新GUI。//
  • 创建一个新的
  • 在线程的方法中创建一个新的线程
  • 当您想要在目标线程上执行某些操作时,请使用处理程序的方法
  • 您可以在主线程上创建一个处理程序来回发更新GUI的操作

    也考虑使用.< /P>