简体   繁体   English

为什么Android JSInterface这么慢?

[英]Why is Android JSInterface so slow?

I have a javascript calling a javascript interface many times (around 500 times sometimes), updating the page's UI from it. 我有一个JavaScript多次调用javascript接口(有时约为500次),并从中更新页面的UI。 It sends a couple strings, and casts String result to string: ""+window.INTERFACENAME.function(...) . 它发送几个字符串,并将String结果转换为字符串: ""+window.INTERFACENAME.function(...)

Without calling the function, it takes 43ms, but takes 6 or 7 seconds with the JSInterface call. 如果不调用该函数,则需要43毫秒,但是使用JSInterface调用则需要6或7秒。 Why is the JSInterface so slow? 为什么JSInterface这么慢?

My solution was to implement the same function in Javascript as the Java code. 我的解决方案是在Javascript中实现与Java代码相同的功能。 Messy, but it's much faster than calling Java. 混乱,但是它比调用Java快得多。 I suppose if it were required to make many calls to Java, it would be better to make one call with a list of inputs. 我想如果需要对Java进行多次调用,最好使用输入列表进行一次调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM