Android WebView with https loadUrl shows blank/empty page

GSON数据解析异常报错java.lang.IllegalArgumentException: Unable to create converter for 创维v5机型gson解析数据造成应用闪退 异常log要点:java.lang.NoSuchMethodError: com.google.gson.Gson.newJsonReader 异常log要点:java.lang.IllegalArgumentException: Unable to create converter for <class> 项目使用框架:retrofit... 阅读详情

Android WebView with https loadUrl shows blank/empty page

September 28, 2010

I recently encountered this problem while trying to develop a WebView that is supported on Doughnut (1.6) and above. When presented with a https url the WebView just renders a blank page.

It seems that until Froyo, Android didn’t provide a public API to let you manually decide if you wanted to proceed to an untrusted web site via a WebView.

Note that in this case it is not even that the web site was untrusted (in the conventional sense) – it is because Thawte is not in the default list of trusted certificate authorities on Android. If you use the standard web browser on Android, the browser presents a typical warning dialog (as presented below) that enables you to accept the certificate and carry on.

Invalid certificate warning

If you are using Froyo as the target SDK then you can use:

1 engine = (WebView) findViewById(R.id.my_webview);
2 engine.setWebViewClient(new WebViewClient() {
3  public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
4  handler.proceed() ;
5  }
6 }

However, if you are not using Froyo then it seems you are out of luck. After some research, I concluded that I had the following options:

a) intercept all page requests and forward to external web browser if url begins with https (not a clean or nice user experience and totally unnecessary for Froyo and above)
b) add certificate of website to local keystore (in this case I am serving multiple web pages and the origin of many of these is not known until runtime)
c) make Froyo the minSDK and discard previous versions of Android (not a suitable option)
d) hack and use some private apis (the option described below)

To solve this problem we have to use a private interface (not published on SDK but present in real SDK runtime). As you can see in the Android src tree, theonReceivedSslError is indeed present (and used – it simply cancels the request) in Doughnut. However, this method is not presented to us in the SDK  - it is hidden because it contains a parameter type SslError which is located in a hidden package.  Therefore, we need to copy these src files into our project so that we can access them:

1) Copy WebViewClient.java into the package “android.webkit” within your src folder.
2) Copy SslError.java into the package “android.net.http” within your src folder.

Src files

3) Since we replicated the paths to the src files in the SDK, our code to override onSslError above now works on Android 1.6.

Caution: bear in mind that we are using a private API and Google reserve the right to change private APIs at any time – though in this case it is unlikely since they’ve now made this available in Froyo.

20 Responses to “Android WebView with https loadUrl shows blank/empty page”

  1. Bano Says:

    Hi, I have used this method and other method (like thishttp://wongcr.blogspot.com/2009/03/disabling-certificate-validation-in.html) and I can’t see a https page in the WebView. Can you help me?


  2. I can try. Your request for help is a bit vague though…

    • Bano Says:

      Sorry, I did’t know if I should write a large post. My problem is with the HttpPost connections, I create an “DefaultHttpClient” and a “HttpPost”, next I create a list of values to send and finally execute it.

      This work in http conections, but in https conections I try the methods I find on Internet and don’t get it to work (Get not trusted certificate).

      The last code (with custom SSLShocketFactory and TrustManager):
      try {
      // //
      SchemeRegistry schemeRegistry = new SchemeRegistry();

      schemeRegistry.register(new Scheme(“https”,new EasySSLSocketFactory(), 443));

      HttpParams params = new BasicHttpParams();
      SingleClientConnManager mgr = new SingleClientConnManager(params, schemeRegistry);

      DefaultHttpClient hc = new DefaultHttpClient(mgr, params);
      // /

      // DefaultHttpClient hc = new DefaultHttpClient();
      ResponseHandler res = new BasicResponseHandler();
      HttpPost postMethod = new HttpPost(DIRECCION);
      List nameValuePairs = new ArrayList(3);
      nameValuePairs.add(new BasicNameValuePair(“usuario”, nom));
      nameValuePairs.add(new BasicNameValuePair(“tipo_firma”, tip));
      nameValuePairs.add(new BasicNameValuePair(“string_img”, img));
      postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));
      String response = hc.execute(postMethod, res);
      return response;
      } catch (ClientProtocolException e) {
      pasos = “Excepción: ” + e.toString();
      } catch (IOException e) {
      // “Error 1: Unable to establish communication with the server. Check your configuration.”
      pasos = pasos + “Excepción: ” + e.toString();
      }

      if you can help me, it would very helpfull.

      PD: Sorry for my bad english…


  3. The best way would be to add the server’s public certificate to your Android App’s trusted store:

    http://blog.crazybob.org/2010/02/android-trusting-ssl-certificates.html

    Otherwise you could simply stop checking all hosts for their certificate:

    http://stackoverflow.com/questions/995514/https-connection-android/1000205#1000205

    • Bano Says:

      Finally, your post give me an idea. I change the DefaultHttpClient for HttpsURLConection, using OutputStream and InputStream to the comunication. Next I apply the second link you give me (I visited it yet but didn’t help me in my previously idea).

      I can’t use the SSL certificate creator because I haven’t direct access to the server of the proyect.

      the code of Send:
      try {
      // //
      String location = “usuario=” + nom + “&tipo_firma=” + tip + “&string_img=” + img;
      URL url = new URL(DIRECCION);
      trustAllHosts();
      HttpsURLConnection https = (HttpsURLConnection) url.openConnection();
      https.setHostnameVerifier(DO_NOT_VERIFY);
      https.setRequestMethod(“POST”);
      https.setDoOutput(true);
      https.setUseCaches(false);
      https.setRequestProperty(“Content-Type”,
      “application/x-www-form-urlencoded”);
      https.connect();
      OutputStream ost = https.getOutputStream();
      DataOutputStream out = new DataOutputStream(ost);
      out.writeBytes(location);
      out.flush();
      ost = null;

      InputStream ist = https.getInputStream();
      BufferedReader in = new BufferedReader(new InputStreamReader(ist));
      StringBuffer sb = new StringBuffer();
      char[] c = new char[1];
      while (in.read(c, 0, 1) == 1) {
      sb.append(c[0]);

      }
      String response = sb.toString();
      // /
      return response;
      } catch (ClientProtocolException e) {
      pasos = “Excepción: ” + e.toString();
      } catch (IOException e) {

      // “Error 1: Unable to establish communication with the server. Check your configuration.”
      pasos = pasos + “Excepción: ” + e.toString();
      }

      Next adding the trust part:
      // always verify the host – dont check for certificate
      final static HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier() {
      public boolean verify(String hostname, SSLSession session) {
      return true;
      }
      };
      /**
      * Trust every server – dont check for any certificate
      */
      private static void trustAllHosts() {
      // Create a trust manager that does not validate certificate chains
      TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
      public java.security.cert.X509Certificate[] getAcceptedIssuers() {
      return new java.security.cert.X509Certificate[] {};
      }

      public void checkClientTrusted(X509Certificate[] chain,String authType) throws CertificateException {}
      public void checkServerTrusted(X509Certificate[] chain,String authType) throws CertificateException {}
      } };

      // Install the all-trusting trust manager
      try {
      SSLContext sc = SSLContext.getInstance(“TLS”);
      sc.init(null, trustAllCerts, new java.security.SecureRandom());
      HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
      } catch (Exception e) {
      e.printStackTrace();
      }
      }

      Thanks for your help.

    • Vito Andolini Says:

      Crazy Bob’s article is a solution for SSL issues with the HttpClient, not with a WebView. I don’t believe you can add a certificate to the app’s trusted store and have that used by a WebView.

  4. William Says:

    Hi,

    Just wanted to thank you to have resolved my problem in 2 seconds.

    Working on eclair 2.1 at the moment I had exactly the same issue you described. Your fixed avoided me a lot of troubles.

    thanks

    William

  5. Ansari Says:

    Thanks a lot, the above solution works.

  6. Sebastian B Says:

    Thank you very much, this is excellent!!!
    I had been struggling with this for some hours before I found your solution.


  7. Thanks, was having the same problem in a project targeting Android 1.6. Now I know what the heck is going on.


  8. [...] WebView just swallowed this with no error messages, but a bit of googling and found the following blog post about how to work round the certificate miss match and even how to make it work with Android [...]

  9. skshelkehelke Says:

    Hi All,
    I am trying to retrieve POST parameter from Response. but not able get it from android Webview.

    Could anyone help me or give an idea to retrieve POST data from response URL.

    Thanks & Regards

  10. Richard Says:

    I have applied your trick and it works fine until I run on a real Android device 1.6 or 2.1. Then the overloading of classes is stop by the DEX loader !!! any tricks to get around ?

    • Richard Says:

      08-15 12:03:41.938: DEBUG/dalvikvm(3003): DexOpt: ‘Landroid/net/http/SslError;’ has an earlier definition; blocking out
      08-15 12:03:41.938: DEBUG/dalvikvm(3003): DexOpt: ‘Landroid/webkit/WebViewClient;’ has an earlier definition; blocking out
      08-15 12:03:41.973: DEBUG/dalvikvm(3003): DexOpt: not verifying ‘Landroid/net/http/SslError;’: multiple definitions
      08-15 12:03:41.973: DEBUG/dalvikvm(3003): DexOpt: not verifying ‘Landroid/webkit/WebViewClient;’: multiple definitions
      08-15 12:03:42.153: INFO/dalvikvm(3003): DexOpt: not resolving ambiguous class ‘Landroid/webkit/WebViewClient;’

  11. tomozeron Says:

    Hi Damian,

    I’ve been struggling a couple of nights getting postUrl to work when posting to a https site. I tried to use all sorts of TrustedManagers etc etc but with no luck.
    Then I found this gem of yours, read it and in less than 10 minutes I was up’n running.

    I bow my head in humble submission.

    Thank you.

    /brian

  12. rpche Says:

    Hello, Damian thnx for the tutorial but i still dont manage to get it work. mayb if u have some time u can help me load https in my webview :)

    package here.testing.a.cool.app;

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.Window;
    import android.webkit.WebChromeClient;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;

    public class WebPageLoader extends Activity
    {
    final Activity activity = this;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);
    this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
    setContentView(R.layout.main);
    WebView webView = (WebView) findViewById(R.id.webview);
    webView.getSettings().setJavaScriptEnabled(true);

    webView.setWebChromeClient(new WebChromeClient() {
    public void onProgressChanged(WebView view, int progress)
    {
    activity.setTitle(“Grabbing the bits and the bytes..”);
    activity.setProgress(progress * 100);

    if(progress == 100)
    activity.setTitle(R.string.app_name);
    }
    });

    webView.setWebViewClient(new WebViewClient() {
    @Override
    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
    {
    // Handle the error
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url)
    {
    view.loadUrl(url);
    return true;
    }
    });

    webView.loadUrl(“https://website.willnot.open”);
    }
    }

  13. Arthur Says:

    Thanks a lot!!!!

  14. becomingthebeast Says:

    Great post Damian.
    As always your articles are most useful.
    Thank you!

YOLO26 从零到工业落地全实战:自定义训练+多场景测试+边缘部署预备,踩坑实测100%可复现 很多人觉得训练是核心,其实不是——数据集的质量,直接决定了你模型的上限。我见过太多人,标注不规范、格式错误、数据集划分混乱,然后疯狂调参,训了几百轮还是不收敛,纯属白费功夫。我这次用的是工业零件缺陷检测自定义数据集,共3个类别:划痕、毛刺、变形,总计1200张图片,给大家讲一套标准的、可复现的数据集制作流程,不管你是做工业检测、安防、交通,都能直接套用。很多人拿到数据集,直接用默认命令训练,然后抱怨精度上不去。默认参数是给COCO数据集用的,你的自定义数据集,必须针对性调参,不然根本达不到最优效果。 阅读详情

相关推荐

浮点数运算的陷阱与启示:FP16加法器/乘法器开发中的常见误区

本文深入探讨FP16加法器和乘法器开发中的常见误区,包括FP16格式解析、阶码对齐陷阱、尾数运算风险及规格化处理。通过Verilog实战代码展示防御性编程技巧,帮助开发者避免边界条件处理和异常状态管理中的错误,提升硬件设计的可靠性和效率。

dell8的博客 252

解决Android Webview 加载一些网页出现白板现象

Webview 加载一些链接出现白板现象,经过调试onLoadResource 已经正常执行,也就是资源文件都已经成功加载,onReceivedSslError也没有回调到,用自带浏览器和UC都是正常,证明链接本身没有问题,Webview也正常运行,没有出现错误,那就是Webview的配置问题了。 经过N个测试,把 webView.getSettings().setJavaScriptEnab

漫漫求学中的孩儿 2万+

STM32F407步进电机控制及DM542驱动器使用

基于DM542驱动器的步进电机简单控制

qq_43868701的博客 1万+

android webview _blank,Android WebView with http loadUrl shows blank/empty page

问题I am developing an Android Application. I want to show web site with WebView. But i don't it. A blank/empty page is opening. The other web site showing but Why this is not showing?My code is belowPl...

weixin_29323493的博客 336

农业杂草检测——棉花杂草数据集

然后将本层13×13的特征图谱经过×2上采样扩充到26×26,并与上层中26×26的特征图谱拼接,得到新的26×26的特征图谱,在该特征尺度上进行第二次预测,此时得到的特征图谱是相对输入图像16倍下采样,具有中尺度感受野,适合检测中等尺度对象;通过目标检测,能够及时清除杂草,减少病虫害的滋生和传播,保障棉花的健康生长,并有助于降低生产成本。对于地膜覆盖的棉田,由于膜内耕作层土温高、底墒好,杂草出苗早而集中,一般覆膜后5 - 7天杂草陆续出土,在墒情好的情况下,15天左右即形成出土高峰。

qq_38220914的博客 1247

2.ROS实用工具:坐标变换

本文围绕ROS坐标变换展开,介绍其在机器人系统中的关键作用,即统一不同传感器和执行器坐标系,服务数据融合等操作。基于ROS的tf库,从广播和监听TF变换两方面阐述实现过程,涵盖新建工作包、编写广播和监听代码、配置构建文件及编译等步骤。此外,介绍启动节点管理器后运行广播和监听节点的方法,并通过rqt_graph、rqt_tf_tree、tf_echo等工具可视化和获取坐标系变换信息。借助这些内容,读者不仅能掌握ROS坐标变换的实现,还能对机器人坐标变换系统的调试和理解有更深入认识 。

qq_74168740的博客 1175

android中使用codec总是报NoSuchMethodError的问题根源

该问题在StackOverflow上有人给出了解决方案,但是更重要的是,下面有一个哥们给出了造成问题的原因分析! 原问题的地址是:http://stackoverflow.com/questions/9126567/method-not-found-using-digestutils-in-android 给出的问题解决方法是: I ran into the same issue t

piglite的专栏 9450

第18届全国大学生智能汽车竞赛四轮车控制策略深度解析:从舵机PID到速度闭环

本文深度解析了第18届全国大学生智能汽车竞赛中四轮车的核心控制策略。从舵机PID方向控制的基础原理与机械校准入手,详细阐述了误差计算、PD控制等关键环节;进而深入探讨了基于编码器的速度闭环控制,包括增量式PI算法与速度决策逻辑。文章结合实战经验,提供了方向环与速度环的协同调参思路与避坑指南,旨在帮助参赛者构建稳定、高效的智能车控制系统。

potato的博客 465

Android Classloader热修复技术之百家齐放

大概在2015年10月底,QQ空间发了一篇叫《安卓App热补丁动态修复技术介绍》的文章,文章中提到为了能让Class进行热修复,其中一个条件就是防止类被打上CLASS_ISPREVERIFIED标记,具体的做法便是让一个Dex引用另一个Dex(hack.apk)中的空类(为了让业务无感知,需要在编译时动态注入字节码),并且在应用程序Application类起来的时候要加载这个hack.apk。也就是

区长的专栏 9555

STM32F103/F407/H743不同GPIO速度配置(HAL库)对应的最高速度

详细介绍了STM32F103/F407/H743不同GPIO速度配置(HAL库)对应的最高速度。

kevin1499的博客 5594

软件设计师高频考点—套路题

学习交流的总结

秩沅 2541

WebView 踩坑记

1. 通过WebView调起继承微信支付的H5页面 // 微信H5 支付 官方测试地址 String url = "http://wxpay.wxutil.com/mch/pay/h5.v2.php"; Map<String, String> extraHeaders = new HashMap<String, String>(); extraHeaders.put("

ZekingLee 1260

YOLOv11改进缝合注意力 | 深度优化的BiFormer模型-结合BiLevel Routing Attention与深度可分离卷积的创新应用(附代码)

YOLO(You Only Look Once)系列目标检测算法一直以来都是计算机视觉领域的热门选择。随着YOLOv11的发布,它在许多实际应用场景中取得了显著的性能提升。然而,面对日益复杂的目标检测任务,单纯依赖卷积神经网络(CNN)在某些情况下已经显得力不从心,特别是在处理小尺度、密集目标以及遮挡目标时,卷积操作的局部性限制了模型的表达能力。

一键难忘的博客 721

Android Visualizer 实战:把声音画出来

是系统提供的音频效果(AudioEffect)之一。它挂在音频链路上,,把数据回吐给你——画波形、画频谱、做响度表。

Android的专栏 312

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

Android 开发入门实践(十三):用 Intent、UiState 和 Reducer 理解 MVI 的状态更新

本文记录第141—145课对MVI架构的入门实践,通过“返回列表”功能逐步构建意图(NewsIntent)、状态(NewsUiState)与状态转换(reduce)机制。基于单向数据流,用户操作生成意图,ViewModel通过Reducer根据旧状态计算新状态,并通过StateFlow更新Compose界面。代码实现清晰分离关注点,强化了对状态管理、事件驱动与数据流的理解。

Easyhood的博客 342

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

Android Message源码阅读

本文梳理了Android Handler机制中Message的核心设计:链表结构、消息复用池(sPool)及回收机制,重点解析了异步消息与同步屏障(SyncBarrier)的协同机制。当主线程需优先处理UI绘制等高优先级任务时,系统通过postSyncBarrier插入屏障,使Looper跳过普通同步消息,优先执行标记为异步的UI渲染任务,确保帧率流畅。该机制是保障Android界面响应性的关键技术之一。

u012116089的博客 214

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

RK-RK3572-Android16- 编译打包优化-OTA整包-差分包打包

这里主要记录一下 RK3572 在Android16 上面进行OTA升级的整包和差分包制作经验的一个分享,整理知识点,方便后续自己和其它同事开发提高工作效率、直接使用。不管哪一个平台,MTK 也好、RK也好 基本上都是不同Android版本各个子系统之间还是有一点点区别的,所以有必要记录整理知识点,方便提高开发效率、生产效率。针对OTA升级问题 ,再一次说明还是要看官方提供的文档,按照文档来。

十年饮冰,难凉热血 205

安卓APK下载后安装全流程:从点击下载到第一次启动,每一步的检查点

这套流程听起来繁琐,但真正需要每次都做的只有来源核对和签名校验两步,其他都是出问题时才查。养成习惯之后,能挡掉绝大多数"装了垃圾包""装完闪退"的情况。如果要省事,直接用这类会标注包名、版本号和校验信息的站点,比在搜索结果里挨个试要稳得多。

qq362196705的专栏 171

Android Laya 与 Native Bridge:页面识别、双向通信、协议设计和崩溃定位

Laya 与 Native 通信的难点不在于某个或的写法,而在于边界:页面来源是否可信、协议是否明确、线程是否正确、请求是否幂等、页面是否仍然存在、日志是否能关联一次完整请求。建立这些边界后,才能把“页面白屏”“按钮无响应”“重复消息”和“Native 崩溃”拆成可验证的层次,并沿着真实调用链找到根因。

路在脚下,幸福在手中,莫贪!!!!! 166

BUUCTF-菜刀流量-MISC-学习笔记

从 1970-01-01 00:00:00 UTC 起算的秒数,——Wireshark 直接告诉你它回答的是谁;由表可知道,96帧返回了flag.rar。, 代表删除键,先删了4次,又删了1次。所以密码是:SuperMaster。解析128帧的响应,即133帧。所以这是一个标准抓包文件,用。解压压缩包拿到html代码。:选中 128 帧,展开。:128 和 131 的。能把一问一答放在一起看;是八进制(Oct)的数字。(或 TCP 层)看到。对比一下ASCii 码表。

晓梦林的博客 80

Android 音频 Player 体系

Android 音频框架中,"Player"是统一抽象的音频播放实例,涵盖 AudioTrack、MediaPlayer 等。每个 Player 由唯一 piid 标识,通过 PlayerBase 注册至 PlaybackActivityMonitor,状态机管理其生命周期(idle→started→stopped→released)。关键事件如 portId 绑定、静音(位掩码标识主静音、音量为0等)、设备切换等均通过 PLAYER_UPDATE_* 通知系统。静音原因以掩码形式记录,日志中“source

aningxiaoxixi的博客 146

Harness篇|DeepSeek Harness 上手机:五条安卓移植路线与 App 内 Linux 拆解

DSH 官方没出安卓版,火的全是社区第三方移植。本文拆解真实卡点(glibc vs Bionic)、两种「App 内 Linux」的实现(PRoot 与 seccomp 容器),以及「真沙箱」的三层边界与衡量标准。

AI_Gump的博客 357

字段获取代码(Android) · Android Input Examples

服务对象可由实际owner缓存,但不因此缓存它返回的号码、运营商或信号。信号与电话网络接口各有权限和设备能力条件,不支持的设备可抛出 UnsupportedOperationException,服务对象非 null 不代表所有电话能力均可用。语言文本还有独立的条件缓存,非null命中时不重读资源或校验格式,地区没有这份文本缓存。slotIndex是逻辑卡槽编号,不能直接传订阅ID,也不替代请求的默认卡读取。是示例自定义的偏好文件名,键名由调用方定义,不是 WhatsApp 的存储文件名或通用字段读取接口。

小乖写代码 190

Android 开发入门实践(九):把新闻数据与页面状态交给 ViewModel

本文记录第110—117课学习成果:将页面标题、新闻列表及选中编号逐步迁移至NewsViewModel,通过ViewModelProvider获取实例并读取数据。页面调用ViewModel方法处理选择与返回,实现状态管理解耦。过程中纠正了对Activity重建机制的误解,并厘清mutableStateOf的可观察性与ViewModel对象生命周期的区别,深化了对Compose状态更新机制的理解。

Easyhood的博客 226

谷歌相机9.2下载(GCam 安卓通用版 安装与使用说明)

谷歌相机9.2版移植自Pixel原生相机,支持Camera2 API的Android 10+设备安装,凭借多帧合成技术在夜景、HDR+与人像模式表现优异。可提升暗光画质、优化动态范围与背景虚化效果,支持视频防抖及配置文件自定义。安装需确认机型兼容性,建议备份原相机,避免冲突。资源可通过kuake链接获取,仅限学习测试使用。

2611_96675819的博客 221

Android 开发入门实践(十):用 Kotlin 协程完成模拟加载、取消与异常处理

本文记录第118—125课对NewsApp的协程改造:从viewModelScope.launch启动协程,逐步加入delay模拟等待、suspend函数封装、withContext(Dispatchers.IO)切换线程并观察上下文恢复机制。通过日志验证withContext完成后恢复原执行上下文(非自动回主线程),纠正了初始理解偏差。引入Job管理任务,实现加载取消与重复点击防护,结合异常处理与状态管理,完成可观察、可中断的异步流程。

Easyhood的博客 413
上一篇: WebView访问HTTPS空白的SslError处理(兼容2.1)
下一篇: Webview html input form not showing/allowing keyboard
OmelasShell
博客等级 码龄15年 5粉丝 6原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值