HarmonyOS bundleManager.getBundleInfoForSelfSync发生jscrash?

调用 bundleManager.getBundleInfoForSelfSync(bundleManager.BundleFlag.GET\_BUNDLE\_INFO\_WITH\_APPLICATION) 发生jscrash,错误信息 Error message:BusinessError 17700101: Bundle manager service is excepted.

代码大致如下

export class Globals {
  static init(appContext: common.ApplicationContext) {
    Globals.sBundleInfo = bundleManager.getBundleInfoForSelfSync(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION)
  }
}

export function initOnCreate(appContext: common.ApplicationContext) {
  globalThis["__taobao_app__"] = appContext; // 将appcontext放到全局变量区
  Globals.init(appContext);
}

export class TaobaoUIAbility extends UIAbility {
  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
    initOnCreate(this.context.getApplicationContext());
  }
}
阅读 532
1 个回答

1.如果不想crash,那需要加上 try catch,根据错误码进行处理,重试 或者 做其他处理

2.不加try catch,出问题 就会crash

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进