示例#1
0
  // Called when UI activities all pause, terminates the service
  // unless canceled.
  //
  public void startBackgroundTimeout() {

    // Cancel any pre-existing timeout.
    cancelBackgroundTimeout();

    Runnable task =
        new Runnable() {
          public void run() {
            mLogger.info("background timeout");
            mApp.doExit();
          }
        };

    String delaystr = mPrefs.getString(SettingsActivity.KEY_BACKGROUND_TIMEOUT, "600");
    long delay;
    try {
      delay = Long.parseLong(delaystr);
    } catch (NumberFormatException ex) {
      throw new RuntimeException(ex.toString()); // Shouldn't happen.
    }

    if (delay != -1) {
      mBackgroundTimeout = mTimeoutWorker.schedule(task, delay, TimeUnit.SECONDS);

      mLogger.info(String.format("background timeout scheduled in %d seconds", delay));
    }
  }
 public void cancelBackgroundTimeout() {
   if (mWalletService != null) mWalletService.cancelBackgroundTimeout();
 }