这是否在 UI 线程上运行

发布于 2024-11-17 05:34:42 字数 620 浏览 3 评论 0原文

这段代码实际上在android(2.2及以上)的UI线程下运行吗?如果没有,有一个如何做到这一点的例子。

在活动中我调用 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);
                }
           }
       });

}

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);
                }
           }
       });

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤檠 2024-11-24 05:34:42

如果您指的是传递给 runOnUiThread 的匿名 Runnable...是的,正如方法名称所示,它肯定会在 UI 线程上运行。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文