uni-app 华为手机执行关闭小程序时间过长
uni-app 华为手机执行关闭小程序时间过长
开发环境 | 版本号 | 项目创建方式 |
---|---|---|
Mac | 11.2.1 | HBuilderX |
产品分类:uniapp/App
PC开发环境操作系统:Mac
PC开发环境操作系统版本号:11.2.1
HBuilderX类型:正式
HBuilderX版本号:2.9.3
手机系统:Android
手机系统版本号:Android 10
手机厂商:华为
手机机型:Mate40
页面类型:nvue
打包方式:离线
App下载地址或H5网址: 线上是ok的
示例代码:
/**
* 释放小程序资源并启动
*/
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, "小程序路径>>>>>>>>>>>>>>>>>>>>");
DCUniMPSDK.getInstance().setUniMPOnCloseCallBack(new DCUniMPSDK.IUniMPOnCloseCallBack() {
@Override
public void onClose(String s) {
LogUtil.d(UniAppWgtUtil.TAG, "小程序路径>>>>>>>>>>>>>>>>>>>>");
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;
}
});
}
更多关于uni-app 华为手机执行关闭小程序时间过长的实战教程也可以访问 https://www.itying.com/category-93-b0.html