blocked the main thread for 71ms. Plugin should use CordovaInterface.getThreadPool()
来源:互联网 发布:ubuntu使用教程pdf 编辑:程序博客网 时间:2024/05/16 13:02
在自己的cordova项目中经常出现一个警告:THREAD WARNING: exec() call to xxxxx.xxxxx blocked the main thread for 71ms. Plugin should use CordovaInterface.getThreadPool().
后来通过看一些人写的cordova教程才知道,如果你不需要在主界面线程运行,但使用WebCore线程,使用下面的方式就不会有这个警告:
@Overridepublic boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { if ("beep".equals(action)) { final long duration = args.getLong(0); cordova.getThreadPool().execute(new Runnable() { public void run() { ... callbackContext.success(); } }); return true; } return false; }
另外cordova插件的JavaScript不在webview界面的主线程中运行,而是在WebCore线程中调用execute方法。如果需要与用户交互(也就是android中的改变ui必须在主线程中)。所以你的cordova插件的java代码如果涉及到了改变ui需要这样写可以保证改变ui的操作一定在主线程中需要这么写:
@Overridepublic boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { if ("beep".equals(action)) { final long duration = args.getLong(0); cordova.getActivity().runOnUiThread(new Runnable() { public void run() { ... callbackContext.success(); } }); return true; } return false; }
0 0
- blocked the main thread for 71ms. Plugin should use CordovaInterface.getThreadPool()
- What NoSQL Store Should I Use? The Right Tool for Your Use Case
- reloadData should be in main thread
- When should I use Thread.getContextClassLoader()?
- When you should use base64 for images
- How the Main Thread works
- Should you use a service or a thread?
- How to Use the Format Fortran Indent Plugin for Code::Blocks ?
- the Eclipse plugin for flex
- Undefined symbols for architecture x86_64: Which architecture should I use?
- Why you should use talloc for your next project
- Blocked Finalizer Thread
- When should I use the Visitor Design Pattern?
- main and the GUI Event Dispatch Thread
- main and the GUI Event Dispatch Thread
- Mercurial Source Control Plugin for MS Visual Studio
- how to use the code in ms ssrs
- should we use annotations?
- Android 三种方式实现自定义圆形页面加载中效果的进度条
- C语言system函数
- C++——算法基础之排序——快速排序
- [httpcomments-client-4.5.2]--源码分析(HTTP request)
- 文件控制ACL
- blocked the main thread for 71ms. Plugin should use CordovaInterface.getThreadPool()
- 以打字形式展示placeholder的插件
- 关于LeetCode中Implement Stack using Queues一题的理解
- CSS3的loader加载动画
- IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) D. Delivery Bears 二分+网络流(循环写二分,否则T。。。)
- 如何利用迅雷下载百度云获取实际下载地址
- spring mvc 配置 log4j
- CXF Attachment接受文件流 (解决)
- 自用零散博文-interfaces.ts