the plugins were executing on the UI thread. now on background thread. calls to loadUrl are now automatically on the ui thread

This commit is contained in:
Dave Johnson 2010-08-07 12:19:04 -07:00
parent 0c52ed44a0
commit 8ca1804de9
2 changed files with 10 additions and 6 deletions

View File

@ -280,9 +280,13 @@ public class DroidGap extends Activity {
} }
} }
public void loadUrl(String url) public void loadUrl(final String url)
{ {
this.appView.loadUrl(url); this.runOnUiThread(new Runnable() {
public void run() {
DroidGap.this.appView.loadUrl(url);
}
});
} }
/** /**

View File

@ -65,12 +65,12 @@ public final class CommandManager {
plugin.setView(this.app); plugin.setView(this.app);
if (async) { if (async) {
// Run this async on the UI thread so that JavaScript can continue on // Run this on a different thread so that this one can return back to JS
app.post(new Runnable() { Thread thread = new Thread(new Runnable() {
public void run() { public void run() {
// Call execute on the plugin so that it can do it's thing // Call execute on the plugin so that it can do it's thing
CommandResult cr = plugin.execute(action, args); CommandResult cr = plugin.execute(action, args);
// Check if the // Check the status for 0 (success) or otherwise
if (cr.getStatus() == 0) { if (cr.getStatus() == 0) {
app.loadUrl(cr.toSuccessCallbackString(callbackId)); app.loadUrl(cr.toSuccessCallbackString(callbackId));
} else { } else {
@ -78,7 +78,7 @@ public final class CommandManager {
} }
} }
}); });
// Return "" thread.start();
return ""; return "";
} else { } else {
// Call execute on the plugin so that it can do it's thing // Call execute on the plugin so that it can do it's thing