Closed acuatoria closed 11 years ago
Looks to be the same problem as described in this issue: https://github.com/Red-Folder/Cordova-Plugin-BackgroundService/issues/7
Could you provide the following please:
1) Cordova Version 2) BackgroundServicePlugin Version 3) More of the logcat ... I'd like to see the messages before the error. This will be the plugin handling the action request. Useful to see the flow of the calls.
At this time I suspect it is how you are calling the plugin methods.
Cordova Plugins are asynchronous. You have to wait for one method to complete (call your success or error callback) before calling another method.
For example, in the above you have:
app.startService( function(r) { setConfig() }, function(e) { handleError(e) } );
app.enableTimer(5000,
function(r) {
handleSuccess(r)
},
function(e) {
handleError(e)
}
);
You need to wait for the callback before performing another app action.
In this case I believe because you are calling the setConfig THEN calling the enableTimer without waiting for the setConfig to finish the two are clashing. This is likely to be a threading issue caused by two threads trying to talk to the Background Service at the same time.
Please refactor your code so that ALL methods wait for the previous success callback before making the next call.
I thought the error was that. Calling functions one after another it works like a charm. I've done several test so I hope it's solved. Thank you very much. Great job.
Excellent news. Thanks for the response back.
This does help to further refine the problem as originally outlines in https://github.com/Red-Folder/Cordova-Plugin-BackgroundService/issues/7
Looks as if I need to put some defensive programming into the Plugin to avoid multiple calls being made to the BackgroundService in parallel (maybe a queue).
But again, thanks for the details and feedback - really does help when tracking down problems.
Hi all, I have an issue that's I hope you can help me At begin of my index.html in order to launch the service if it's not launched I have this code and If I comment the app.setConfiguration it doesn't crash Thank you in advance
// THE CODE
function setConfig() {
}
app.stopService( function(r){handleSuccess(r)}, function(e){handleError(e)});
app.disableTimer( function(r){handleSuccess(r)}, function(e){handleError(e)});
app.deregisterForBootStart();
app.registerForBootStart(); email="" clave=""
app.getStatus(function(result) { // checking if the service was not previously started if (!result.ServiceRunning) { // starting the background service
-- THE ERROR
08-22 18:17:07.272: D/CordovaNetworkManager(6960): Connection Type: wifi 08-22 18:17:07.282: D/BackgroundServicePluginLogic(6960): Exception - null 08-22 18:17:07.302: W/dalvikvm(6960): threadid=19: thread exiting with uncaught exception (group=0x40ab0300) 08-22 18:17:07.332: I/BackgroundService(6960): Service creating 08-22 18:17:07.332: I/BackgroundService(6960): Initialising the service 08-22 18:17:07.332: I/BackgroundService(6960): Syncing result 08-22 18:17:07.362: E/AndroidRuntime(6960): FATAL EXCEPTION: pool-1-thread-2 08-22 18:17:07.362: E/AndroidRuntime(6960): java.lang.NullPointerException 08-22 18:17:07.362: E/AndroidRuntime(6960): at org.apache.cordova.api.PluginResult.(PluginResult.java:52)
08-22 18:17:07.362: E/AndroidRuntime(6960): at org.apache.cordova.api.CallbackContext.error(CallbackContext.java:125)
08-22 18:17:07.362: E/AndroidRuntime(6960): at com.red_folder.phonegap.plugin.backgroundservice.BackgroundServicePlugin$1.run(BackgroundServicePlugin.java:55)
08-22 18:17:07.362: E/AndroidRuntime(6960): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
08-22 18:17:07.362: E/AndroidRuntime(6960): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
08-22 18:17:07.362: E/AndroidRuntime(6960): at java.lang.Thread.run(Thread.java:856)
08-22 18:17:07.382: I/BackgroundService(6960): Service started
08-22 18:17:07.392: I/BackgroundService(6960): onBind called