コード例 #1
0
 @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;
   }
 }
コード例 #2
0
 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;
 }
コード例 #3
0
 @Override
 public void onDestroy() {
   super.onDestroy();
   Commons.log(Constants.TAG_BINDING_PACKAGE_SERVICE, Constants.SERVICE_DESTROYED);
 }
コード例 #4
0
 @Override
 public boolean stopService(Intent name) {
   Commons.log(Constants.TAG_BINDING_PACKAGE_SERVICE, Constants.SERVICE_STOPPED);
   stopService = true;
   return super.stopService(name);
 }
コード例 #5
0
 @Override
 public void onCreate() {
   super.onCreate();
   Commons.log(Constants.TAG_BINDING_PACKAGE_SERVICE, Constants.SERVICE_CREATED);
 }
コード例 #6
0
 @Override
 public boolean onUnbind(Intent intent) {
   Commons.log(Constants.TAG_BINDING_PACKAGE_SERVICE, Constants.SERVICE_UNBOUND);
   return super.onUnbind(intent);
 }
コード例 #7
0
 @Override
 public IBinder onBind(Intent intent) {
   Commons.log(Constants.TAG_BINDING_PACKAGE_SERVICE, Constants.SERVICE_BOUND);
   return binder;
 }
コード例 #8
0
 @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);
 }
コード例 #9
0
 @Override
 protected void onProgressUpdate(Integer... progress) {
   Commons.log(Constants.TAG_BINDING_PACKAGE_SERVICE, progress[0] + "% downloaded");
 }
コード例 #10
0
 @Override
 protected void onCancelled() {
   super.onCancelled();
   Commons.log(Constants.TAG_BINDING_PACKAGE_SERVICE, "Download task canceled");
 }