/**
* 释放小程序资源并启动
*/
public static void releaseWgtAndStart(Context mContext, UniAppWgtUtil.OnErrorListener errorListener) {
String runingAppid = DCUniMPSDK.getInstance().getRuningAppid();
if (!TextUtils.isEmpty(runingAppid) && !TextUtils.equals(runingAppid, UniAppWgtUtil.formattedUniAppId)) {
LogUtil.d(UniAppWgtUtil.TAG, "小程序路径>>>>>>11111111111111111111111");
DCUniMPSDK.getInstance().setUniMPOnCloseCallBack(new DCUniMPSDK.IUniMPOnCloseCallBack() {
@Override
public void onClose(String s) {
LogUtil.d(UniAppWgtUtil.TAG, "小程序路径>>>>>>22222222222222222222222");
DCUniMPSDK.getInstance().setUniMPOnCloseCallBack(null);
releaseWgtAndStart(mContext, errorListener);
}
});
DCUniMPSDK.getInstance().closeCurrentApp();
return;
}
String wgtPath = UniAppWgtUtil.getWgtPath();
LogUtil.d(UniAppWgtUtil.TAG, "小程序路径>>>>>>" + wgtPath);
DCUniMPSDK.getInstance().releaseWgtToRunPathFromePath(UniAppWgtUtil.formattedUniAppId, wgtPath, new ICallBack() {
@Override
public Object onCallBack(int code, Object object) {
if (code == 1 && DCUniMPSDK.getInstance().isInitialize()) {
try {
JSONObject arguments = new JSONObject(UniAppWgtUtil.arguments);
DCUniMPSDK.getInstance().startApp(mContext, UniAppWgtUtil.formattedUniAppId, null, UniAppWgtUtil.redirectPath, arguments);
//传参,防止重复打开的情况下,小程序获取不到值
Util.getHandler(mContext).postDelayed(new Runnable() {
@Override
public void run() {
String runingAppid = DCUniMPSDK.getInstance().getRuningAppid();
if (!TextUtils.isEmpty(runingAppid) && TextUtils.equals(UniAppWgtUtil.formattedUniAppId, runingAppid)) {
sendUniMPEvent(arguments);
}
}
}, 500L);
} catch (Exception e) {
if (errorListener != null)
errorListener.doError(e.getMessage());
}
if (mContext instanceof Activity)
((Activity) mContext).finish();
} else {
CustomToast.showToast(mContext, String.format("小程序打开失败,错误码:%d", code));
FileHelper.deleteFile(new File(wgtPath));
if (mContext instanceof UniMPStyle1Activity)
((Activity) mContext).finish();
}
return null;
}
});
}

- 发布:2021-03-01 10:55
- 更新:2021-03-01 10:55
- 阅读:587
产品分类: uniapp/App
PC开发环境操作系统: Mac
PC开发环境操作系统版本号: 11.2.1
HBuilderX类型: 正式
HBuilderX版本号: 2.9.3
手机系统: Android
手机系统版本号: Android 10
手机厂商: 华为
手机机型: Mate40
页面类型: nvue
打包方式: 离线
项目创建方式: HBuilderX
App下载地址或H5⽹址: 线上是ok的
示例代码:
操作步骤:
重复打开一个小程序
重复打开一个小程序
预期结果:
白屏+二次点击
白屏+二次点击
实际结果:
白屏+二次点击
白屏+二次点击
bug描述:
执行小程序关闭之后,关闭时间过长。
因为小程序单进程问题,2个小程序切换打开的时候需要先关闭上一个小程序,所以在关闭过程中打印,时间比较长,耗时是9s,导致2个问题
1、因为关闭过程等待,需要二次点击触发。
2、重复切换情况下,会出现白屏问题,其实真是原因是上一次关闭小程序造成。
