Example #1
0
  private void doRequest() {
    Tracer.methodEnter();
    Preferences.setLastUpdateTime(this, calendar.getTimeInMillis());

    RequestTask<List<VideoData>> currentUpdateRequest =
        new YouTubeGetNewVideoRequest(
            this,
            new HandleErrorRequestCallback<List<VideoData>>() {
              @Override
              public void onResult(RequestTask<List<VideoData>> requestTask) {
                if (Preferences.getServerRunning(TaskService.this)) {
                  TrackEvent trackEvent = createEvent(requestTask.getResult());
                  Intent intent = new Intent(TrackerListenerImpl.TRACK_EVENT_ACTION);
                  intent.putExtra(TrackerListenerImpl.TRACK_EVENT_EXTRA, trackEvent);

                  TaskService.this.sendBroadcast(intent);
                }

                Tracer.debug("Update result: \n " + requestTask.getResult().toString());
              }

              @Override
              public void onError(Exception e) {
                Tracer.debug("Exception when data is updating!!! " + e.getMessage());
              }
            });
    requestExecutor.asyncRequest(currentUpdateRequest);
  }
Example #2
0
  private void doIteration() {
    Tracer.methodEnter();
    long lastUpdateTime = Preferences.getLastUpdateTime(this);
    long diff = calendar.getTimeInMillis() - lastUpdateTime;
    boolean needRequest = diff > DELAY_BETWEEN_REQUEST_MILLISECONDS;

    if (needRequest) {
      doRequest();
    }
  }
Example #3
0
 @Override
 protected void onHandleIntent(Intent intent) {
   Tracer.methodEnter("task_service");
   doIteration();
 }