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);
}
發佈callGetConnectedUserWS(「Please wait ...」)的代碼;你在線程中更新ui嗎? – Raghunandan
如果您正在更新線程中的UI,然後嘗試使用asyncTask – Shruti
我從服務器獲取響應並處理處理程序中的響應後更新UI – hharry