In what thread are the methods of CallbackContext
supposed to be called?
The documentation for CordovaPlugin#execute(...)
says it's called in the WebView thread. Is that the same as the UI thread? If so, then that's probably my answer.
If the WebView thread is not the UI thread, and I'm supposed to call back in the WebView thread, is it possible to do so asynchronously?
I put you the Threading section of the android plugins documentation. The plugins are all asynch, when you call them you get a success or failure callback. The theads are just to not block the UI if the native task is too long.
http://docs.phonegap.com/en/3.5.0/guide_platforms_android_plugin.md.html#Android%20Plugins
Note from Kevin:
Calls to the methods of
CallbackContext
end up callingCordovaWebView#sendPluginResult(PluginResult cr, String callbackId)
. The implementation of that method inCordovaWebViewImpl
callsNativeToJsMessageQueue#addPluginResult(cr, callbackId)
, which ultimately results in an element being added to aLinkedList
inside a synchronized block. All accesses to thatList
are synchronized