codenameoneでモバイルアプリを開発しています
サーバーに接続して、サーバーからデータを取得する必要があります。
データを取得するときに、ダイアログボックスを表示したいと思います。
ただし、アプリがデータをフェッチするのを永遠に待たないようにする必要もあります。のように、特定の期間(たとえば、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.
私が知りたいのは、「私はこれを正しく行っているのか」ということです。接続要求が強制終了され、漂遊スレッドが実行されていないことを確認するにはどうすればよいですか?
私が達成しようとしていることを達成するためのより良い方法はありますか?