解决java.lang.IllegalStateException: Calling View methods on another thread than the UI thread
来源:互联网 发布:上海夏易网络怎么样 编辑:程序博客网 时间:2024/05/17 06:45
在android4.4+版本中,webview的使用发生了一些改变:
见文档:http://developer.android.com/intl/zh-cn/guide/webapps/migrating.html
我们的工程中要收集userAgent,在4.4之后就不能在主线程new webview了,因此使用文档中提供的方法:
If you need to retrieve the user agent but don't need to store it for your app or do not want to instantiateWebView
, you should use the static method, getDefaultUserAgent()
. However, if you intend to override the user agent string in your WebView
, you may instead want to use getUserAgentString()
.
代码如下:
public static String getUserAgent(Context ctx) {//api 19 之前if(Build.VERSION.SDK_INT < 19){WebView webview = new WebView(ctx);WebSettings settings = webview.getSettings();return settings.getUserAgentString();}//api >=19return WebSettings.getDefaultUserAgent(ctx); }
0 0
- 解决java.lang.IllegalStateException: Calling View methods on another thread than the UI thread
- 【已解决】Calling View methods on another thread than the UI thread.
- Calling View methods on another thread than the UI thread.错误
- 关于Calling View methods on another thread than the UI thread的错误
- 关于Calling View methods on another thread than the UI thread的错误
- java.lang.Throwable: Warning: A WebView methods must be called on the same thread.
- java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.
- java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.
- java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.
- java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.
- java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.
- java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.
- java.lang.IllegalStateException: Hardware acceleration can only be used with a single UI thread.
- android4.1 JELLY_BEAN:All WebView methods must be called on the same thread[问题已解决]
- Cause by:All WebView methods must be called on the same thread[问题已解决]
- RxJava:java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.
- 使用retrofit+rxjava报java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread
- Fatal Exception: java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.
- ios Location 获取坐标
- java.security.InvalidKeyException:illegal Key Size
- 创建不同类型的用户参数
- C++数组与指针小结
- android 获取包下的类
- 解决java.lang.IllegalStateException: Calling View methods on another thread than the UI thread
- 发布网站时应该把debug设置false
- Android adapter
- getRequestURL()与getQueryString()获取用户请求URL
- Intellij setup with Java configuration
- Android 性能检测整理
- 网络基本功系列:细说路由(上)
- 如何提高电子产品的抗干扰能力和电磁兼容
- JDK8中JavaFX如何使用和JDK7一样的风格