Thread에서 Message로 정보를 넘길때 Object obj는 어떤것을 의미하는거죠?

 

public void handleMessage (Message msg)

필드

설명

int what

메세지의 의미를 설명한다. 의미가 정해져 있지는 않으며 핸들러로 지역적이므로 다른 핸들러와 충돌할 위험은 없다.

int arg1

메세지의 추가 정보이다.

int arg2

메세지의 추가 정보이다.

Object obj

정수만으로 메세지를 기술할 수 없을 때 임의의 객체를 보낸다.

Messenger reply to

메세지에 대한 응답을 받을 객체를 지정한다.

 

여기서 what은 핸들 구분인것 같고, arg1과 arg2는 정수값을 넘겨 줄 수 있는것 같은데,

만약에 float 타입의 값을 3개 정도 넘겨줄려면 Object obj로 넘겨줘야 하나요?

예제는 전부 int형 1개만 넘겨주는것라서 잘 모르겠습니다.

그리고 넘겨 받는쪽도 함께 알려주시면 감사하겠습니다.

Messenger reply to 사용법도 설명해주시면 감사하겠습니다.

 

 

 public class C16_Handler extends Activity {
 int mMainValue = 0;
 TextView mMainText;
 TextView mBackText;
 BackThread mThread;
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.c16_thread);
  mMainText = (TextView)findViewById(R.id.mainvalue);
  mBackText = (TextView)findViewById(R.id.backvalue);
  mThread = new BackThread(mHandler);
  mThread.setDaemon(true);
  mThread.start();
 }
 public void mOnClick(View v) {
  mMainValue++;
  mMainText.setText("MainValue : " + mMainValue);
 }
 Handler mHandler = new Handler() {
     public void handleMessage(Message msg) {
      if (msg.what == 0) {
    mBackText.setText("BackValue : " + msg.arg1);
      }
     }
    };
}

 

 class BackThread extends Thread {
 int mBackValue = 0;
 Handler mHandler;
 BackThread(Handler handler) {
  mHandler = handler;
 }
 public void run() {
  while (true) {
   mBackValue++;
   Message msg = Message.obtain(mHandler, 0, mBackValue, 0);
   mHandler.sendMessage(msg);
   try { Thread.sleep(1000); } catch (InterruptedException e) {;}
  }
 }
}