rvecnuvyiiiivjeei
New Member
I have created a plugin that starts a service and this is working fine. However I wish to be able to send variables to the running service from the plugin, and to get variables out of the service. I have researched broadcast/receivers and binding but haven't be able to to get any examples working with the code structure I am using below. Does anyone have any tips? I'm new to android development and pretty new to Java (but not programming) so there is a conceptual leap that I haven't quite got yet.\[code\]public class IOIOconnect extends CordovaPlugin { private Context thiscontext; private Intent ioioService; // Handle calls from Javascript @Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { // Call from javascript to startup the IOIO service if (action.equals("ioioStartup")) { this.ioioStartup(callbackContext); return true; } } // Initialise IOIO service (Called from Javascript) private void ioioStartup(CallbackContext callbackContext) { // Initialise the service variables and start it it up thiscontext = this.cordova.getActivity().getApplicationContext(); ioioService = new Intent(thiscontext, HelloIOIOService.class); ioioService.putExtra("loadinterval", 800); // Set LED flash interval thiscontext.startService(ioioService); }}public class HelloIOIOService extends IOIOService { private int interval = 100; @Override public IBinder onBind(Intent intent) { return null; } // USUAL IOIO SERVICE STUFF @Override public void onStart(Intent intent, int startId) { // Service has been started super.onStart(intent, startId); // IOIO When service is started load external vars (if set) int loadinterval = intent.getIntExtra("loadinterval", -1); if(loadinterval>=0){ interval = loadinterval; } // Native IOIO stuff NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); if (intent != null && intent.getAction() != null && intent.getAction().equals("stop")) { // User clicked the notification. Need to stop the service. nm.cancel(0); stopSelf(); } else { // Service starting. Create a notification. Notification notification = new Notification( R.drawable.ic_launcher, "IOIO service running", System.currentTimeMillis()); notification .setLatestEventInfo(this, "IOIO Service", "Click to stop", PendingIntent.getService(this, 0, new Intent( "stop", null, this, this.getClass()), 0)); notification.flags |= Notification.FLAG_ONGOING_EVENT; nm.notify(0, notification); } }}\[/code\]