使用http.HttpRequest.request发起http请求后,在promise的then回调里执行自定义回调函数,但是回调到页面代码后,调用toast会报错[ArkRuntime Log] Error: Internal error. UI execution context not found.
操作步骤:
1、http.createHttp();创建请求
2、request.request;发起请求
3、promise.then中处理数据然后执行回调函数
4、回调函数中使用promptAction.showToast进行输出toast
根据报错信息:Internal error. UI execution context not found.是在调用promptAction.showToast接口时,接口识别到场景下UI实例缺失主动抛出的。绑定UI实例来调用接口,同时进行合理的try catch异常捕捉。 demo如下: