2013-06-05 5 views
0
I have to call a webserbice in every 10 seconds for this I am using Timer. But I am getting Exception like Can't create handler inside thread that has not called Looper.prepare(). 

my code for calling ws: 

Timer timer = new Timer(); 
    TimerTask timerTask = new TimerTask() { 
     @Override 
     public void run() { 
      callGetConnectedUserWS("Please wait..."); 
     } 
     }; 
timer.schedule(timerTask, 0, 10000); 


public void callGetConnectedUserWS(String msg, int getConnectedUsersPID) { 
    if (NetworkAvailablity.getInstance().checkNetworkStatus(FriendActivity.this)) { 
      WebServiceCommunicator.getInstance().registerForServerResponse(FriendActivity.this); 
ServerRequestParams serverRequestParams = null; 
HashMap<String, String> properties = new HashMap<String, String>(); 
    properties.put("username", _myUserName); 

    serverRequestParams = new ServerRequestParams(getParent(), properties, WebServiceDetails.METHOD_NAME_GET_CONNECTED_USERS, WebServiceDetails.URL_WS_USER, msg); 
       WebServiceCommunicator.getInstance().callWebService(FriendActivity.this, serverRequestParams, getConnectedUsersPID); 

} else { 
     Constant.ShowAlertDialog("",Constant.MSG_INTERNETERROR, getParent(), false); 
    } 

}타이머

+0

스레드에서 UI를 업데이트하고 있습니까? – Raghunandan

+0

스레드에서 UI를 업데이트 한 다음 asyncTask를 사용하려고 시도하면 – Shruti

+0

서버에서 응답을 받고 처리기에서 응답을 처리 한 후 UI를 업데이트합니다. – hharry

답변

0

에 비누 웹 서비스를 호출하는 방법을 당신은 백그라운드 스레드에서

Constant.ShowAlertDialog("",Constant.MSG_INTERNETERROR, getParent(), false);

를 호출 할 수 없습니다. UI 스레드에서 경고 대화 상자를 표시해야합니다. callGetConnectedUserWS ("Please wait ...") 코드를 게시하려면 UI 대화 상자에서 경고 대화 상자를 표시해야합니다.