package com.nbusy.app;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.support.v4.content.LocalBroadcastManager;

import java.util.Objects;

public class WorkerService extends Service {

    private LocalBroadcastManager lbm; // send results back to caller from background threads..

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

    @Override
    public IBinder onBind(Intent intent) {
        // pass in the instance of this local service so binder can call methods directly on it
        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;
    }
}

@@ -76,16 +76,42 @@
 Intent;%0A
+import android.os.Binder;%0A
 import a
@@ -121,32 +121,32 @@
 oid.os.IBinder;%0A
-
 import android.s
@@ -272,16 +272,85 @@
 private 
+final IBinder binder = new WorkerServiceBinder();%0A%0A    private final 
 LocalBro
@@ -366,16 +366,23 @@
 ager lbm
+ = null
 ; // sen
@@ -612,115 +612,21 @@
     
-// pass in the instance of this local service so binder can call methods directly on it%0A        return null
+return binder
 ;%0A  
@@ -1411,11 +1411,220 @@
 Y;%0A    %7D
+%0A%0A    public class WorkerServiceBinder extends Binder %7B%0A        WorkerService getService() %7B%0A            return WorkerService.this;%0A        %7D%0A    %7D%0A%0A    public boolean getRunning() %7B%0A        return true;%0A    %7D
 %0A%7D%0A

allow binding to the worker service