SyncService.java 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package de.tudarmstadt.informatik.hostage.sync.android;
  2. import android.app.Service;
  3. import android.content.Intent;
  4. import android.os.IBinder;
  5. import android.util.Log;
  6. /**
  7. * Created by abrakowski
  8. */
  9. public class SyncService extends Service {
  10. private static final String TAG = "SyncService";
  11. private static final Object sSyncAdapterLock = new Object();
  12. private static SyncAdapter sSyncAdapter = null;
  13. /**
  14. * Thread-safe constructor, creates static {@link SyncAdapter} instance.
  15. */
  16. @Override
  17. public void onCreate() {
  18. super.onCreate();
  19. Log.i(TAG, "Service created");
  20. synchronized (sSyncAdapterLock) {
  21. if (sSyncAdapter == null) {
  22. sSyncAdapter = new SyncAdapter(getApplicationContext(), true);
  23. }
  24. }
  25. }
  26. @Override
  27. /**
  28. * Logging-only destructor.
  29. */
  30. public void onDestroy() {
  31. super.onDestroy();
  32. Log.i(TAG, "Service destroyed");
  33. }
  34. /**
  35. * Return Binder handle for IPC communication with {@link SyncAdapter}.
  36. *
  37. * <p>New sync requests will be sent directly to the SyncAdapter using this channel.
  38. *
  39. * @param intent Calling intent
  40. * @return Binder handle for {@link SyncAdapter}
  41. */
  42. @Override
  43. public IBinder onBind(Intent intent) {
  44. return sSyncAdapter.getSyncAdapterBinder();
  45. }
  46. }