2012-03-06 2 views
0

은 내가 어떤 메시지를 표시해야하는 웹 서비스 호출 응답에 근거하여 비누 웹 서비스 호출을 사용하고 자식 스레드에서는. 내 응용 프로그램에서

을 주요 THEAD의 메소드를 호출하지만 응답 후 나는 할 수 없었다 메인 스레드 다시 연락이 분명하다

희망을 가지고 내가 응답 한 후이 표시 .. 내 요구 사항을 달성하는 방법을 도와하는 방법

그래서 양산 자식 스레드에서이 작업을 수행 할 수

{ 
Thread t1 = new Thread() { 
public void run() { 

    String threadName = Thread.currentThread().getName(); 
    // There will be delay in this statement while fetching a data from webservice 
    String returnfromWebservice = webservice(xmlDetails, "generateid"); 
    Log.v("returnfromWebservice",returnfromWebservice); 
    if( ! returnfromWebservice.equalsIgnoreCase("nil")){ 
     gotid = returnfromWebservice; 
     gotReply=true; 
    // dothis();// I could able to do this because this method contains widgets 
    // I am gettin the error : Only the original thread that created a view hierarchy can touch its views. 
    //I understand this is because childthread has no controls on widget 
    /**Suggest me how to get back to main thread*/ 
    } 
    }}; 
t1.start(); 
dothis();// so i am doin here after the completion of it 


} 

public void dothis{ 
if(gotReply){ 
    idtext.setText(gotid); 
    genId.setEnabled(false); 
    Toast.makeText(WelcomeScorer.this, "Generated ", 500).show(); 
} 
else{ 
    Toast.makeText(WelcomeScorer.this, "Try Once More ", 500).show(); 
    idtext.setText(gotid); 
} 
} 

나는 안드로이드에 익숙하지 만,이 상황을 처리하기위한 안드로이드 API에 대한 최선의 접근 방법이 있습니까 ??

답변

2

당신은 다른 스레드에서

youractivityname.this.runOnUiThread(new Runnable() { 

      @Override 
      public void run() { 
       // TODO Auto-generated method stub 

      } 
     }); 

당신의 UI 요소를 터치 다음 코드를 사용합니다. 그렇지 않으면 활동 클래스 오브젝트를 사용하여 위의 메소드를 실행해야합니다.
코드에서 dothis()를 호출해야합니다. 실이 끝난 후에 스레드가 작업을 시작했는지 여부에 상관없이 스레드가 시작된 직후에 dothis 메서드를 호출합니다.

1

다양한 방법은 this article에 설명되어 있습니다. 아마도 runOnUiThread을 사용하는 것이 가장 간단 할 것입니다. 당신이 사용할 수있는 스레드가 같은 활동에 있으면

관련 문제