당신은 적어도 3 개 개의 스레드를 가지고 , 스레드 2 (ConnectThread를 생성하는 스레드)와 스레드 3 (다른 범위의 스레드)에서 사용할 수있는 것이 필요합니다.
ConnectedThread thread = new ConnectedThread(btSocket);
ThreadHolder.connectedThread=thread;
thread.start();
에서 : 스레드 2에서
public class ThreadHolder{
public static ConnectedThread connectedThread
}
당신이 참조를 설정 :
간단한 방법은 스레드의 참조를 보유하고 정적 변수와 클래스 ThreadHolder을 가지고, 수 스레드 3을 찾으셨습니까?
또는 ConnectedThread에 다음을 제공 할 수 있습니다. 스레드 2 이름 :
thread.setName ("connectedThread")
그리고이 방법을 사용하여 htread 3에서 찾을 :
public Thread getThreadByName(String threadName) {
for (Thread t : Thread.getAllStackTraces().keySet()) {
if (t.getName().equals(threadName)) return t;
}
return null;
}
도 find thread by name
참조