コード例 #1
0
  /**
   * Entry point to add a new operation to the queue of operations.
   *
   * <p>New operations are added calling to startService(), resulting in a call to this method. This
   * ensures the service will keep on working although the caller activity goes away.
   */
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    Log_OC.d(TAG, "Starting command with id " + startId);

    // WIP: for the moment, only SYNC_FOLDER is expected here;
    // the rest of the operations are requested through the Binder
    if (ACTION_SYNC_FOLDER.equals(intent.getAction())) {

      if (!intent.hasExtra(EXTRA_ACCOUNT) || !intent.hasExtra(EXTRA_REMOTE_PATH)) {
        Log_OC.e(TAG, "Not enough information provided in intent");
        return START_NOT_STICKY;
      }
      Account account = intent.getParcelableExtra(EXTRA_ACCOUNT);
      String remotePath = intent.getStringExtra(EXTRA_REMOTE_PATH);

      Pair<Account, String> itemSyncKey = new Pair<Account, String>(account, remotePath);

      Pair<Target, RemoteOperation> itemToQueue = newOperation(intent);
      if (itemToQueue != null) {
        mSyncFolderHandler.add(
            account, remotePath, (SynchronizeFolderOperation) itemToQueue.second);
        Message msg = mSyncFolderHandler.obtainMessage();
        msg.arg1 = startId;
        msg.obj = itemSyncKey;
        mSyncFolderHandler.sendMessage(msg);
      }

    } else {
      Message msg = mOperationsHandler.obtainMessage();
      msg.arg1 = startId;
      mOperationsHandler.sendMessage(msg);
    }

    return START_NOT_STICKY;
  }
コード例 #2
0
  @Override
  public void onDestroy() {
    Log_OC.v(TAG, "Destroying service");
    // Saving cookies
    try {
      OwnCloudClientManagerFactory.getDefaultSingleton()
          .saveAllClients(this, MainApp.getAccountType());

      // TODO - get rid of these exceptions
    } catch (AccountNotFoundException e) {
      e.printStackTrace();
    } catch (AuthenticatorException e) {
      e.printStackTrace();
    } catch (OperationCanceledException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    mUndispatchedFinishedOperations.clear();

    mOperationsBinder = null;

    mOperationsHandler.getLooper().quit();
    mOperationsHandler = null;

    mSyncFolderHandler.getLooper().quit();
    mSyncFolderHandler = null;

    super.onDestroy();
  }