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);
   }

}

4

1 回答 1

0

你不能打电话

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

从后台线程。您需要从 UI 线程显示警报对话框

runOnUIThread(new Runnable() {
 @Override 
void run() {
   Constant.ShowAlertDialog("",Constant.MSG_INTERNETERROR, getParent(), false);
  }
}
于 2013-06-05T10:58:08.143 回答