Back to project page tape.
The source code is released under:
Apache License
If you think the Android project tape listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
// Copyright 2012 Square, Inc. package com.squareup.tape.sample; /* w ww. j a va 2s. c o m*/ import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.util.Log; import com.squareup.otto.Bus; import com.squareup.tape.sample.ImageUploadTask.Callback; import javax.inject.Inject; public class ImageUploadTaskService extends Service implements Callback { private static final String TAG = "Tape:ImageUploadTaskService"; @Inject ImageUploadTaskQueue queue; @Inject Bus bus; private boolean running; @Override public void onCreate() { super.onCreate(); ((SampleApplication) getApplication()).inject(this); Log.i(TAG, "Service starting!"); } @Override public int onStartCommand(Intent intent, int flags, int startId) { executeNext(); return START_STICKY; } private void executeNext() { if (running) return; // Only one task at a time. ImageUploadTask task = queue.peek(); if (task != null) { running = true; task.execute(this); } else { Log.i(TAG, "Service stopping!"); stopSelf(); // No more tasks are present. Stop. } } @Override public void onSuccess(final String url) { running = false; queue.remove(); bus.post(new ImageUploadSuccessEvent(url)); executeNext(); } @Override public void onFailure() { } @Override public IBinder onBind(Intent intent) { return null; } }