2012-08-12 6 views
0

모바일 앱을 개발 중입니다. codenameonejava/codename one에서 요청 시간 초과를 처리하는 방법은 무엇입니까?

서버에 연결하고 서버에서 데이터를 가져와야합니다.

데이터를 가져 오면 대화 상자를 표시하고 싶습니다.

그러나 앱이 데이터를 가져 오기 위해 영원히 기다리지 않도록해야합니다. 마찬가지로 특정 시간 (예 : 5 초) 동안 데이터를 가져 오지 않으면 서버 연결 요청을 중지하고 '데이터를 가져 오지 못했습니다.'라는 메시지를 표시하고 싶습니다.

그래서 .. 나는 현재하는 일입니다 내가 알고 싶은 것은

1)declare a timerTask which has the following line: 

    NetworkManager.getInstance().addToQueueAndWait(c); //c is my connection object and i have //implemented the method readResponse() in it. 

2)The method readResponse has a string which stores data fetched from server. this string is global and has a default value of "-1". 

3)schedule a timer to run for every 5 secs with the above timerTask. 

4)On the second run of the timer, I check if my string's value (which stores data fetched from server;) has changed. If it has, i show the string in the dialog box else, I just say that data not fetched. 

5)Cancel the timertask and the timer. 

: "내가 제대로이 일이 있습니까?" 연결 요청이 종료되고 스트레이 스레드가 실행되지 않도록하려면 어떻게합니까?

달성하려는 목표를 달성하는 더 좋은 방법이 있습니까?

답변

1

NetworkManager.setTimeout()을 사용하지 않으시겠습니까?

+0

아 ... 감사합니다. .. – Nikhil

관련 문제