@Override public int onStartCommand(Intent intent,int flags,int startId){
  Log_OC.d(TAG,"Starting command with id " + startId);
  if (!intent.hasExtra(EXTRA_ACCOUNT) || !intent.hasExtra(EXTRA_FILE)) {
    Log_OC.e(TAG,"Not enough information provided in intent");
    return START_NOT_STICKY;
  }
 else {
    final Account account=intent.getParcelableExtra(EXTRA_ACCOUNT);
    final OCFile file=intent.getParcelableExtra(EXTRA_FILE);
    AbstractList<String> requestedDownloads=new Vector<>();
    try {
      DownloadFileOperation newDownload=new DownloadFileOperation(account,file);
      newDownload.addDatatransferProgressListener(this);
      newDownload.addDatatransferProgressListener((FileDownloaderBinder)mBinder);
      Pair<String,String> putResult=mPendingDownloads.putIfAbsent(account,file.getRemotePath(),newDownload);
      String downloadKey=putResult.first;
      requestedDownloads.add(downloadKey);
      sendBroadcastNewDownload(newDownload,putResult.second);
    }
 catch (    IllegalArgumentException e) {
      Log_OC.e(TAG,"Not enough information provided in intent: " + e.getMessage());
      return START_NOT_STICKY;
    }
    if (requestedDownloads.size() > 0) {
      Message msg=mServiceHandler.obtainMessage();
      msg.arg1=startId;
      msg.obj=requestedDownloads;
      mServiceHandler.sendMessage(msg);
    }
  }
  return START_NOT_STICKY;
}

@ Override public int onStartCommand ( Intent intent , int flags , int startId ) { Log_OC . d ( TAG , "Starting command with id " + startId ) ; if ( ! intent . hasExtra ( EXTRA_ACCOUNT ) || ! intent . hasExtra ( EXTRA_FILE ) ) { Log_OC . e ( TAG , "Not enough information provided in intent" ) ; return START_NOT_STICKY ; } else { final Account account = intent . getParcelableExtra ( EXTRA_ACCOUNT ) ; final OCFile file = intent . getParcelableExtra ( EXTRA_FILE ) ; AbstractList < String > requestedDownloads = new Vector < > ( ) ; try { DownloadFileOperation newDownload = new DownloadFileOperation ( account , file ) ; newDownload . addDatatransferProgressListener ( this ) ; newDownload . addDatatransferProgressListener ( ( FileDownloaderBinder ) mBinder ) ; Pair < String , String > putResult = mPendingDownloads . putIfAbsent ( account , file . getRemotePath ( ) , newDownload ) ; String downloadKey = putResult . first ; requestedDownloads . add ( downloadKey ) ; sendBroadcastNewDownload ( newDownload , putResult . second ) ; } catch ( IllegalArgumentException e ) { Log_OC . e ( TAG , "Not enough information provided in intent: " + e . getMessage ( ) ) ; return START_NOT_STICKY ; } if ( requestedDownloads . size ( ) > 0 ) { Message msg = mServiceHandler . obtainMessage ( ) ; msg . arg1 = startId ; msg . obj = requestedDownloads ; mServiceHandler . sendMessage ( msg ) ; } } return START_NOT_STICKY ; }
entry point to add one or several files to the queue of downloads . < p / > new downloads 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 .
