在用到socket的时候,一般手机都是客户端,不可避免的用到socket接收线程,接收从服务器发来的一些信息,当想退出时,肯定要结束掉这个接收线程,比如说下面的run函数
public void run()
{
// TODO Auto-generated method stub
while(flag)
{
if(!socket.isClosed() && socket.isConnected() && in != null)
{
try
{
String result = in.readLine();
if(result == null || result.length() <= 0)
{
}
else
{
System.out.println(result);
}
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
return;
}
}
try
{
Thread.sleep(500);
}
catch(Exception e)
{
e.printStackTrace();
return;
}
}
}
然后想结束时,先将flag置为false,再执行下面的CloseSocket函数
public void CloseSoc