package com.nbusy.app;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

import java.util.Objects;

public class WorkerService extends Service {

    // whether to terminate after task queue is done or keep running
    private boolean terminateAfterDone;

    @Override
    public IBinder onBind(Intent intent) {
        // don't allow direct binding to this service
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();

        // todo: initiate connection to nbusy server using neptulon json-rpc java client (or nbusy java client which wraps that and auto-adds all routes)?
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        // terminate the service after queued tasks are done if service was started
        // by device boot event and application is not actively running
        String startedBy = intent.getStringExtra("StartedBy");
        terminateAfterDone = (startedBy != null && Objects.equals(startedBy, "DeviceBootReceiver"));

        // we want this service to continue running until it is explicitly stopped, so return sticky
        return Service.START_STICKY;
    }
}

@@ -102,16 +102,73 @@
 IBinder;
+%0Aimport android.support.v4.content.LocalBroadcastManager;
 %0A%0Aimport
@@ -234,16 +234,113 @@
 vice %7B%0A%0A
+    private LocalBroadcastManager lbm; // send results back to caller from background threads..%0A%0A
     // w
@@ -513,50 +513,92 @@
  // 
-don't allow direct binding to this service
+pass in the instance of this local service so binder can call methods directly on it
 %0A   

add notes