A设备利用startAbility拉起B设备的UIAbility时,A设备page里的代码如下:
let bundleFlag = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE
let bundleInfo = bundleManager.getBundleInfoForSelfSync(bundleFlag)
let want: Want = {
deviceId: AppStorage.get('selectDeviceId') as string,
bundleName: bundleInfo.name,
moduleName: bundleInfo.hapModulesInfo[0].name,
abilityName: 'EntryAbility',
parameters: { selectMusicIndex: AppStorage.get('selectMusicIndex') as number }
}
hilog.debug(0x0001, 'RemoteDeviceManager_send', JSON.stringify(want.deviceId))
hilog.debug(0x0001, 'RemoteDeviceManager_send', JSON.stringify(want.bundleName))
hilog.debug(0x0001, 'RemoteDeviceManager_send', JSON.stringify(want.moduleName))
hilog.debug(0x0001, 'RemoteDeviceManager_send', JSON.stringify(want.abilityName))
hilog.debug(0x0001, 'RemoteDeviceManager_send', JSON.stringify(want.parameters))
let context = getContext(this) as common.UIAbilityContext
context.startAbility(want)
.then(() => hilog.debug(0x0001, 'RemoteDeviceManager_send', 'send success'))
.catch((error: BusinessError) => hilog.debug(0x0001, 'RemoteDeviceManager_send', JSON.stringify(error)))
A设备UIAbility的onContinue如下:
onContinue(wantParam: Record<string, number>): AbilityConstant.OnContinueResult {
//
return AbilityConstant.OnContinueResult.AGREE
}
我在startAbility时已经保存了参数,onContinue里还需要保存吗?如果需要,应该怎么写才能保存参数?
目前onContinue还没写,A设备startAbility时会报错,错误码401,官网文档错误码链接:通用错误码401
在这种情况下,onContinue是否需要保存参数取决于你的具体业务需求。如果在后续的业务逻辑中需要用到这些参数,那么可以在 onContinue中进行保存。以下是一个示例,展示如何在 onContinue中处理参数保存: