gpt4 book ai didi

java - Android Javascript 界面

转载 作者:行者123 更新时间:2023-11-29 22:07:59 24 4
gpt4 key购买 nike

我有一个带有javascript 方法
的 WebView 调用 android Javascript Interface(JAVA) 方法,然后
Javscript Interface(JAVA) 调用 context(Reader) Activity 的方法 以打开 UI 屏幕.

当我直接从 ReaderActivity 运行 openDiscussionsUI() 时,它可以正常打开 UI,但当它从 Javascript 界面运行时,它似乎没有完全运行 openDiscussionsUI() 方法,就好像它被中断了? 希望有人能帮我解决这个问题。提前致谢。



javascript方法

marginIconClick: function (itemId) {
activity.startDiscussionsActivity();
}



(JAVA) JavaScript 接口(interface)方法

public void startDiscussionsActivity() {
readerActivity.openDiscussionsUI();
Log.e("startDiscussionsActivity","startDiscussionsActivity");
}



ReaderActivity 方法

public void openDiscussionsUI() {
Log.e("openDiscussionsUI 1","openDiscussionsUI 1");
discussionBox.startAnimation(slidenotesup);
Log.e("openDiscussionsUI 2","openDiscussionsUI 2");
discussionBox.setVisibility(View.VISIBLE);
Log.e("openDiscussionsUI 3","openDiscussionsUI 3");
discussionDescription.requestFocus();
Log.e("openDiscussionsUI 4","openDiscussionsUI 4");
}



这是我的日志
单击图标编号 #1

11-06 17:21:39.190  12951-12980/com.double_eye.monamiq E/openDiscussionsUI 1﹕ openDiscussionsUI 1
11-06 17:21:39.190 12951-12980/com.double_eye.monamiq E/openDiscussionsUI 2﹕ openDiscussionsUI 2


单击图标 #2

11-06 17:22:32.154  12951-12980/com.double_eye.monamiq E/openDiscussionsUI 1﹕ openDiscussionsUI 1
11-06 17:22:32.154 12951-12980/com.double_eye.monamiq E/openDiscussionsUI 2﹕ openDiscussionsUI 2
11-06 17:22:32.154 12951-12980/com.double_eye.monamiq E/openDiscussionsUI 3﹕ openDiscussionsUI 3
11-06 17:22:32.170 12951-12951/com.double_eye.monamiq I/WEBVIEW﹕ Message - 266:Uncaught Error: Error calling method on NPObject.


单击图标 #3

11-06 17:22:52.818  12951-12980/com.double_eye.monamiq E/openDiscussionsUI 1﹕ openDiscussionsUI 1
11-06 17:22:52.818 12951-12980/com.double_eye.monamiq E/openDiscussionsUI 2﹕ openDiscussionsUI 2
11-06 17:22:52.818 12951-12980/com.double_eye.monamiq E/openDiscussionsUI 3﹕ openDiscussionsUI 3
11-06 17:22:52.818 12951-12980/com.double_eye.monamiq E/openDiscussionsUI 4﹕ openDiscussionsUI 4
11-06 17:22:52.818 12951-12980/com.double_eye.monamiq E/startDiscussionsActivity﹕ startDiscussionsActivity


单击图标编号 #4

11-06 17:23:37.850  12951-12980/com.double_eye.monamiq E/openDiscussionsUI 1﹕ openDiscussionsUI 1
11-06 17:23:37.850 12951-12980/com.double_eye.monamiq E/openDiscussionsUI 2﹕ openDiscussionsUI 2
11-06 17:23:37.850 12951-12980/com.double_eye.monamiq E/openDiscussionsUI 3﹕ openDiscussionsUI 3
11-06 17:23:37.850 12951-12980/com.double_eye.monamiq E/openDiscussionsUI 4﹕ openDiscussionsUI 4
11-06 17:23:37.850 12951-12980/com.double_eye.monamiq E/startDiscussionsActivity﹕ startDiscussionsActivity



第3、4次都跑完了,还是不显示ui,很奇怪。

更新:

来自 Javascript 接口(interface)的回调未在 UI 线程上运行

公共(public)无效测试(){ //调用AndroidInterface.test()后1ms到达这里。到达网络线程。

public void startDiscussionsActivity() {
runOnUiThread(new Runnable() {
@Override
public void run() {
readerActivity.openDiscussionsUI();
Log.e("startDiscussionsActivity","startDiscussionsActivity");
}
});
}

最佳答案

确保任何用户界面工作都在主 (UI) 线程上执行。 JavaScript 接口(interface)回调到一个单独的线程,这意味着您需要调用 myActivity.runOnUiThread() 或类似的函数。

关于java - Android Javascript 界面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19818649/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com