@Override public int onStartCommand(Intent intent, int flags, int startId) { if (urls == null) { Commons.log(Constants.TAG_BINDING_PACKAGE_SERVICE, Constants.SERVICE_NOT_STARTED); stopSelf(); return START_STICKY; } else { stopService = false; Commons.log(Constants.TAG_BINDING_PACKAGE_SERVICE, Constants.SERVICE_STARTED); new BackgroundTask(this, intent).execute(urls); // We want this service to continue running until it is explicitly stopped, so return sticky. return START_STICKY; } }
private int DownloadFile(URL url) { Commons.log(Constants.TAG_BINDING_PACKAGE_SERVICE, "Downloading: " + url); Mock.getInstance().pause(TIME_BETWEEN_DOWNLOADS); // Return an arbitrary number representing the size of the file downloaded return 100; }
@Override public void onDestroy() { super.onDestroy(); Commons.log(Constants.TAG_BINDING_PACKAGE_SERVICE, Constants.SERVICE_DESTROYED); }
@Override public boolean stopService(Intent name) { Commons.log(Constants.TAG_BINDING_PACKAGE_SERVICE, Constants.SERVICE_STOPPED); stopService = true; return super.stopService(name); }
@Override public void onCreate() { super.onCreate(); Commons.log(Constants.TAG_BINDING_PACKAGE_SERVICE, Constants.SERVICE_CREATED); }
@Override public boolean onUnbind(Intent intent) { Commons.log(Constants.TAG_BINDING_PACKAGE_SERVICE, Constants.SERVICE_UNBOUND); return super.onUnbind(intent); }
@Override public IBinder onBind(Intent intent) { Commons.log(Constants.TAG_BINDING_PACKAGE_SERVICE, Constants.SERVICE_BOUND); return binder; }
@Override protected void onPostExecute(Long result) { Commons.log(Constants.TAG_BINDING_PACKAGE_SERVICE, "Downloaded " + result + " bytes"); // This will stop the service after finishing the task service.stopService(intent); }
@Override protected void onProgressUpdate(Integer... progress) { Commons.log(Constants.TAG_BINDING_PACKAGE_SERVICE, progress[0] + "% downloaded"); }
@Override protected void onCancelled() { super.onCancelled(); Commons.log(Constants.TAG_BINDING_PACKAGE_SERVICE, "Download task canceled"); }