user94437
user94437

Reputation: 149

Does this Run on the UI thread

Does this code actually run under the UI thread in android (2.2 & up). If not is there an example of how to do it.

In activity I call the JSInterface

  class Xyz extends Activity implements OnInitListener () {
        ...
        engine.addJavascriptInterface(new DemoJavaScriptInterface(), "demo");
  }


final class DemoJavaScriptInterface {

    DemoJavaScriptInterface() {
    }


    public void clickOnAndroid(final String num) {
        runOnUiThread(new Runnable() {
           public void run() {
                if (isrunning) {
                         _tts.speak(num,TextToSpeech.QUEUE_FLUSH, null);
                }
           }
       });

}

Upvotes: 1

Views: 1639

Answers (1)

Maximus
Maximus

Reputation: 8431

If you're referring to the anonymous Runnable passed to runOnUiThread... yes, that will definitely run on the UI Thread as the method name suggests.

Upvotes: 1

Related Questions