안드로이드 개발 질문/답변
(글 수 358)
제가 쓰레드를 공부하던중에 핸들러를 넘겨서 쓰레드로 수정한 값이 Ui에 적용되게 하는 예제를 봤는데,
메인 Activity파일에서 Thread 생성할때 handler를 생성자를 통해 넘겨주고, 이 handler를 이용해서 Activity에 메세지를 전달해 UI를 수정하는 방식입니다.
밑은 Thread 파일입니다.
public class BackThread extends Thread {
private Handler mHandler;
int cnt=0;
public BackThread(Handler handler)
{
mHandler = handler;
}
public void run()
{
while(true)
{
Message msg = Message.obtain();
msg.what=0;
msg.arg1=cnt++;
mHandler.sendMessage(msg);
try{
Thread.sleep(1000);
}
catch(Exception e){}
}
}
}
여기서 궁금한점이, Thread에서 Handler를 받을때 call by value로 받아져 왔을텐데, 여기서 보낸 메세지가 Activity에서도 그대로 쓰입니다.
Handler는 자동으로 call by reference로 넘겨지나요?
Java는 전부 call by reference 입니다. 기본 형식들 빼구요.