2010-12-06 1 views
0

약간의 역사를 제공하기 위해 기본적으로 자식 스레드에서 메시지로 직렬화 할 수없는 객체 (스팬)를 주 스레드로 보냅니다. 나는 그것을 명백하게 시도했다. 그것을 바이트 배열로 바꾸고 그것을 보내는 것이지만, 직렬화 가능을 구현하지 않기 때문에 에러가 발생한다.핸들러에 직렬화 할 수없는 객체 전달하기 (자식 스레드에서)

번들을 사용하여 보낼 수있는 다른 방법이 있습니까? 또는 다른 것? 여기

내가 메인 스레드 핸들러가 자식 스레드 여기

// message and bundle for the questions explanation 
Message qemsg = messageHandler.obtainMessage(); 

Bundle qeb = new Bundle(); 
qeb.putString("questionExplanations", questionExplanations); 

qemsg.setData(qeb); 
qemsg.arg1 = 0; 
messageHandler.sendMessage(qemsg); 

에서 메시지입니다 보내고있다 방법이다 (아이 스레드에서 보낸 메시지 수신) :

여기
private Handler messageHandler = new Handler() { 
    @Override 
    public void handleMessage(Message msg) { 
    CFAData cd = CFAData.getSingletonObject(); 
    Bundle summaryBundle = msg.getData(); 

    switch(msg.arg1) { 
     case 0: 
     // receives the bundle here and does what it needs on the UI thread 
     //testQuestionsExplanations.append(spannedExplanationsObj); 

     break; 
     default: 
     break; 
    } 
    } 
}; 
+0

한 프로세스에 두 개의 스레드가있는 경우 왜 단순하지 않은 것입니까? thread간에 전송되는 객체의 참조 또는 복제를 전달합니까? – Robert

답변

4

이 방법을 메시지에 임의의 개체를 첨부하십시오.

qemsg.obj = mySpanned; 
+0

오 대단하네요! 감사! – xil3

관련 문제