diff --git a/src/main/java/com/nutomic/syncthingandroid/WebGuiActivity.java b/src/main/java/com/nutomic/syncthingandroid/WebGuiActivity.java index a06ab4c2..2c461de5 100644 --- a/src/main/java/com/nutomic/syncthingandroid/WebGuiActivity.java +++ b/src/main/java/com/nutomic/syncthingandroid/WebGuiActivity.java @@ -99,12 +99,7 @@ public class WebGuiActivity extends Activity implements SyncthingService.OnWebGu */ @Override public void onWebGuiAvailable() { - runOnUiThread(new Runnable() { - @Override - public void run() { - mWebView.loadUrl(mSyncthingService.getApi().getUrl()); - } - }); + mWebView.loadUrl(mSyncthingService.getApi().getUrl()); } @Override diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingService.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingService.java index f588413e..26ddfc1d 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingService.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingService.java @@ -200,9 +200,9 @@ public class SyncthingService extends Service { * Polls SYNCTHING_URL until it returns HTTP status OK, then calls all listeners * in mOnWebGuiAvailableListeners and clears it. */ - private class PollWebGuiAvailableRunnable implements Runnable { + private class PollWebGuiAvailableTask extends AsyncTask { @Override - public void run() { + protected Void doInBackground(Void... voids) { int status = 0; HttpClient httpclient = new DefaultHttpClient(); HttpHead head = new HttpHead(mApi.getUrl()); @@ -225,7 +225,11 @@ public class SyncthingService extends Service { Log.w(TAG, "Failed to poll for web interface", e); } } while(status != HttpStatus.SC_OK); + return null; + } + @Override + protected void onPostExecute(Void aVoid) { Log.i(TAG, "Web GUI has come online at " + mApi.getUrl()); mIsWebGuiAvailable = true; for (OnWebGuiAvailableListener listener : mOnWebGuiAvailableListeners) { @@ -328,7 +332,7 @@ public class SyncthingService extends Service { new PostTask().execute(mApi.getUrl(), PostTask.URI_SHUTDOWN, apiKey); registerOnWebGuiAvailableListener(mApi); } - new Thread(new PollWebGuiAvailableRunnable()).start(); + new PollWebGuiAvailableTask().execute(); runNative(); } }).start(); @@ -358,8 +362,6 @@ public class SyncthingService extends Service { * * If the web gui is already available, listener will be called immediately. * Listeners are unregistered automatically after being called. - * - * Note that the listener might be called on a background thread. */ public void registerOnWebGuiAvailableListener(OnWebGuiAvailableListener listener) { if (mIsWebGuiAvailable) {