title: Android - Unexpected setExecutionWindow() behaviour in OneoffTask.Builder
body: <p>I am creating a <code>GcmTaskService</code> which I call with a <code>OneoffTask</code>.</p>
  
  <p>I am not sure the <code>windowEndDelaySeconds</code> value I pass to the <code>setExecution()</code> method of <code>OneoffTask.Builder</code> is being utilised correctly. Or maybe I just don't understand the <a href="https://developers.google.com/android/reference/com/google/android/gms/gcm/OneoffTask.Builder.html#setExecutionWindow(long,%20long)" rel="nofollow noreferrer">documentation for OneoffTask.Builder's setExecution()</a>:</p>
  
  <blockquote>
    <p><strong>public OneoffTask.Builder setExecutionWindow (long windowStartDelaySeconds, long windowEndDelaySeconds)</strong></p>
    
    <p>Mandatory setter for creating a one-off task. You specify the earliest
    point in time in the future from which your task might start
    executing, as well as the latest point in time in the future at which
    your task must have executed.</p>
    
    <p><strong>Parameters</strong></p>
    
    <p>windowStartDelaySeconds - Earliest point from which your task is eligible to run. windowEndDelaySeconds - Latest point at
    which your task must be run.</p>
  </blockquote>
  
  <p>When I do the following:</p>
  
  <ol>
  <li>Disable connectivity on my device</li>
  <li>Schedule my task with an end time of 1 second - using <code>.setExecutionWindow(0, 1)</code></li>
  <li>Wait 10 seconds</li>
  <li>Enable connectivity on my device</li>
  </ol>
  
  <p>...my task executes - despite it being much later than the 1 second <code>windowEndDelaySeconds</code> value I specified in the <code>OneoffTask.Builder</code>. Why is this?</p>
  
  <p><strong>My code</strong></p>
  
  <pre><code>import android.content.Context;
  import android.os.Bundle;
  import android.util.Log;
  import com.google.android.gms.gcm.GcmNetworkManager;
  import com.google.android.gms.gcm.GcmTaskService;
  import com.google.android.gms.gcm.OneoffTask;
  import com.google.android.gms.gcm.Task;
  import com.google.android.gms.gcm.TaskParams;
  
  public class TestTaskService extends GcmTaskService {
  
      private final static String LOG_TAG = TestTaskService.class.getSimpleName();
      private static final String ACTION_TEST = "ACTION_TEST";
      private static final String EXTRA_ACTION = "EXTRA_ACTION";
      private static final String EXTRA_MESSAGE = "EXTRA_MESSAGE";
  
      public static void startActionTest(Context context, String message) {
  
          Bundle extras = new Bundle();
          extras.putString(EXTRA_ACTION, ACTION_TEST);
          extras.putString(EXTRA_MESSAGE, message);
  
          OneoffTask task = new OneoffTask.Builder()
                  .setService(TestTaskService.class)
                  .setExtras(extras)
                  .setTag(ACTION_TEST)
                  .setExecutionWindow(0, 1) // seconds
                  .setRequiredNetwork(Task.NETWORK_STATE_CONNECTED)
                  .setPersisted(true)
                  .setUpdateCurrent(true)
                  .build();
  
          GcmNetworkManager gcmNetworkManager = GcmNetworkManager.getInstance(context);
          gcmNetworkManager.schedule(task);
  
      }
  
      @Override
      public int onRunTask(TaskParams taskParams) {
  
          Context context = getApplicationContext();
          Bundle extras = taskParams.getExtras();
          String action = extras.getString(EXTRA_ACTION);
          if (ACTION_TEST.equals(action)) {
  
              String message = extras.getString(EXTRA_MESSAGE);
              if (message == null) {
                  message = "No message.";
              }
              Utilities.makeToast(context, message);
              return GcmNetworkManager.RESULT_SUCCESS;
          }
          else {
              Log.e(LOG_TAG, "Unknown action: " + action);
              Utilities.makeToast(context, "Unknown action: " + action);
              return GcmNetworkManager.RESULT_FAILURE;
          }
  
      }
  
  }
  </code></pre>
  
  <p>...called with <code>TestTaskService.startActionTest(context, "My message");</code></p>