这是否在 UI 线程上运行
这段代码实际上在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您指的是传递给 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.