Code example for ScheduledExecutorService

Methods: isShutdown, schedule

0
    onActivity(); 
  } 
 
  void onActivity() { 
    cancel(); 
    if (!inactivityTimer.isShutdown()) {
      try { 
        inactivityFuture = inactivityTimer.schedule(new FinishListener(activity),
            INACTIVITY_DELAY_SECONDS,
            TimeUnit.SECONDS);
      } catch (RejectedExecutionException ree) {
        // surprising, but could be normal if for some reason the implementation just doesn't 
        // think it can shcedule again. Since this time-out is non-essential, just forget it 
      } 
    } 
  } 
 
  public void onPause() { 
    cancel(); 
    activity.unregisterReceiver(powerStatusReceiver);
  }