import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.os.IBinder;
-import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.LocalBroadcastManager;
* @author Marius Gavrilescu <marius@ieval.ro>
*/
private final class LongPollRunnable implements Runnable{
- /**
- * Minimum time between two runs of the long polling service, in milliseconds
- *
- * This ensures the long polling service won't use up all your mobile data.
- */
- private static final int MIN_MILLIS_BETWEEN_RUNS = 10000;
-
public void run(){
final ConnectivityManager man=(ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
final HttpCallExecutableRunnable runnable=new HttpCallExecutableRunnable("/get", null, FonBotMainService.this, new PollResultCallback(FonBotMainService.this), false);
Log.d("LongPollRunnable", "Long polling started");
- long lastRun = 0;
while(man.getActiveNetworkInfo() != null && man.getActiveNetworkInfo().isConnected())
try {
- if(lastRun + MIN_MILLIS_BETWEEN_RUNS > System.currentTimeMillis())
- SystemClock.sleep(lastRun + MIN_MILLIS_BETWEEN_RUNS - System.currentTimeMillis());
- else
- runnable.run();
+ runnable.run();
} catch (final Exception ex){
ex.printStackTrace();
break;