From 20a859691e8fb3301bceb6c409f15c1f12180807 Mon Sep 17 00:00:00 2001 From: wangyong Date: Fri, 16 Jun 2023 17:08:45 +0800 Subject: [PATCH] update doc of moveMissionsToForegound/moveMissionsToBackground Signed-off-by: wangyong --- .../js-apis-app-ability-missionManager.md | 312 ++++++++++++++++++ 1 file changed, 312 insertions(+) diff --git a/zh-cn/application-dev/reference/apis/js-apis-app-ability-missionManager.md b/zh-cn/application-dev/reference/apis/js-apis-app-ability-missionManager.md index 15ea77ce7f..0aea4cf5c7 100755 --- a/zh-cn/application-dev/reference/apis/js-apis-app-ability-missionManager.md +++ b/zh-cn/application-dev/reference/apis/js-apis-app-ability-missionManager.md @@ -1098,3 +1098,315 @@ try { console.error('moveMissionToFront failed. Cause: ${error.message}'); } ``` + +## missionManager.moveMissionsToForeground10+ + +moveMissionsToForeground(missionIds: Array<number>, callback: AsyncCallback<void>): void; + +将指定任务批量切到前台,以回调函数的方式返回。 + +**需要权限**:ohos.permission.MANAGE_MISSIONS + +**系统能力**:SystemCapability.Ability.AbilityRuntime.Mission + +**系统接口**: 此接口为系统接口。 + +**参数:** + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | + | missionIds | Array<number> | 是 | 任务ID数组。 | + | callback | AsyncCallback<void> | 是 | 执行结果回调函数。 | + +**错误码**: + +以下错误码的详细介绍请参见[errcode-ability](../errorcodes/errorcode-ability.md)。 + +| 错误码ID | 错误信息 | +| ------- | -------- | +| 16000050 | Internal error. | + +**示例:** + +```ts +import abilityManager from '@ohos.app.ability.abilityManager'; +import missionManager from '@ohos.app.ability.missionManager'; + +try { + missionManager.getMissionInfos("", 10, (error, missionInfos) => { + if (error.code) { + console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code)); + return; + } + if (missionInfos.length < 1) { + return; + } + + let toShows = new Array(); + for (let missionInfo of missionInfos) { + if (missionInfo.abilityState == abilityManager.AbilityState.BACKGROUND) { + toShows.push(missionInfo.missionId); + } + } + missionManager.moveMissionsToForeground(toShows, (err, data) => { + if (err) { + console.error('moveMissionsToForeground failed: ${err.message}'); + } else { + console.info('moveMissionsToForeground successfully: ${JSON.stringify(data)}'); + } + }); + }); +} catch (paramError) { + console.log("error: " + paramError.code + ", " + paramError.message); +} + +``` + +## missionManager.moveMissionsToForeground10+ + +moveMissionsToForeground(missionIds: Array<number>, topMission: number, callback: AsyncCallback<void>): void; + +将指定任务批量切换到前台,并将任务ID等于topMission的任务移动到最顶层,以回调函数的方式返回。 + +**需要权限**:ohos.permission.MANAGE_MISSIONS + +**系统能力**:SystemCapability.Ability.AbilityRuntime.Mission + +**系统接口**: 此接口为系统接口。 + +**参数:** + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | + | missionIds | Array<number> | 是 | 任务ID数组。 | + | topMission | number | 是 | 待移动到最顶层的任务ID | + | callback | AsyncCallback<void> | 是 | 执行结果回调函数。 | + +**错误码**: + +以下错误码的详细介绍请参见[errcode-ability](../errorcodes/errorcode-ability.md)。 + +| 错误码ID | 错误信息 | +| ------- | -------- | +| 16000050 | Internal error. | + +**示例:** + +```ts +import abilityManager from '@ohos.app.ability.abilityManager'; +import missionManager from '@ohos.app.ability.missionManager'; + +try { + missionManager.getMissionInfos("", 10, (error, missionInfos) => { + if (error.code) { + console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code)); + return; + } + if (missionInfos.length < 1) { + return; + } + + let toShows = new Array(); + for (let missionInfo of missionInfos) { + if (missionInfo.abilityState == abilityManager.AbilityState.BACKGROUND) { + toShows.push(missionInfo.missionId); + } + } + missionManager.moveMissionsToForeground(toShows, toShows[0], (err, data) => { + if (err) { + console.error('moveMissionsToForeground failed: ${err.message}'); + } else { + console.info('moveMissionsToForeground successfully: ${JSON.stringify(data)}'); + } + }); + }); +} catch (paramError) { + console.log("error: " + paramError.code + ", " + paramError.message); +} + +``` + +## missionManager.moveMissionsToForeground10+ + +moveMissionsToForeground(missionIds: Array<number>, topMission?: number): Promise<void>; + +将指定任务批量切到前台,并将任务ID等于topMission的任务移动到最顶层,以promise的方式返回。 + +**需要权限**:ohos.permission.MANAGE_MISSIONS + +**系统能力**:SystemCapability.Ability.AbilityRuntime.Mission + +**系统接口**: 此接口为系统接口。 + +**参数:** + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | + | missionIds | Array<number> | 是 | 任务ID数组。 | + | topMission | number | 否 | 待移动到最顶层的任务ID | + +**返回值:** + + | 类型 | 说明 | + | -------- | -------- | + | Promise<void> | promise方式返回执行结果。 | + +**错误码**: + +以下错误码的详细介绍请参见[errcode-ability](../errorcodes/errorcode-ability.md)。 + +| 错误码ID | 错误信息 | +| ------- | -------- | +| 16000050 | Internal error. | + +**示例:** + +```ts +import abilityManager from '@ohos.app.ability.abilityManager'; +import missionManager from '@ohos.app.ability.missionManager'; + +try { + missionManager.getMissionInfos("", 10, (error, missionInfos) => { + if (error.code) { + console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code)); + return; + } + if (missionInfos.length < 1) { + return; + } + + let toShows = new Array(); + for (let missionInfo of missionInfos) { + if (missionInfo.abilityState == abilityManager.AbilityState.BACKGROUND) { + toShows.push(missionInfo.missionId); + } + } + missionManager.moveMissionsToForeground(toShows, toShows[0]).then(() => { + console.log("moveMissionsToForeground is called" ); + }); + }); +} catch (paramError) { + console.log("error: " + paramError.code + ", " + paramError.message); +} + +``` + +## missionManager.moveMissionsToBackground10+ + +moveMissionsToBackground(missionIds: Array<number>, callback: AsyncCallback<Array<number>>): void; + +将指定任务批量切到后台,以回调函数的方式返回, 返回的结果任务ID按被隐藏时的任务层级排序。 + +**需要权限**:ohos.permission.MANAGE_MISSIONS + +**系统能力**:SystemCapability.Ability.AbilityRuntime.Mission + +**系统接口**: 此接口为系统接口。 + +**参数:** + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | + | missionIds | Array<number> | 是 | 任务ID数组。 | + | callback | AsyncCallback<Array<number>> | 是 | 执行结果回调函数。 | + +**错误码**: + +以下错误码的详细介绍请参见[errcode-ability](../errorcodes/errorcode-ability.md)。 + +| 错误码ID | 错误信息 | +| ------- | -------- | +| 16000050 | Internal error. | + +**示例:** + +```ts +import abilityManager from '@ohos.app.ability.abilityManager'; +import missionManager from '@ohos.app.ability.missionManager'; + +try { + missionManager.getMissionInfos("", 10, (error, missionInfos) => { + if (error.code) { + console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code)); + return; + } + + let toHides = new Array(); + for (let missionInfo of missionInfos) { + if (missionInfo.abilityState == abilityManager.AbilityState.FOREGROUND) { + toHides.push(missionInfo.missionId); + } + } + missionManager.moveMissionsToBackground(toHides, (err, data) => { + if (err) { + console.error('moveMissionsToBackground failed: ${err.message}'); + } else { + console.info('moveMissionsToBackground successfully: ${JSON.stringify(data)}'); + } + }); + }); +} catch (paramError) { + console.log("error: " + paramError.code + ", " + paramError.message); +} +``` + +## missionManager.moveMissionsToBackground10+ + +moveMissionsToBackground(missionIds : Array<number>): Promise<Array<number>>; + +将指定任务批量切到后台,以promise的方式返回, 返回的结果按被隐藏时的任务层级排序。 + +**需要权限**:ohos.permission.MANAGE_MISSIONS + +**系统能力**:SystemCapability.Ability.AbilityRuntime.Mission + +**系统接口**: 此接口为系统接口。 + +**参数:** + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------- | -------- | -------- | + | missionIds | Array<number> | 是 | 任务ID数组。 | + +**返回值:** + + | 类型 | 说明 | + | -------- | -------- | + | Promise<Array<number>> | promise方式返回执行结果。 | + +**错误码**: + +以下错误码的详细介绍请参见[errcode-ability](../errorcodes/errorcode-ability.md)。 + +| 错误码ID | 错误信息 | +| ------- | -------- | +| 16000050 | Internal error. | + +**示例:** + +```ts +import abilityManager from '@ohos.app.ability.abilityManager'; +import missionManager from '@ohos.app.ability.missionManager'; + +try { + missionManager.getMissionInfos("", 10, (error, missionInfos) => { + if (error.code) { + console.log("getMissionInfos failed, error.code:" + JSON.stringify(error.code)); + return; + } + + let toHides = new Array(); + for (let missionInfo of missionInfos) { + if (missionInfo.abilityState == abilityManager.AbilityState.FOREGROUND) { + toHides.push(missionInfo.missionId); + } + } + missionManager.moveMissionsToBackground(toHides).then((hideRes) => { + console.log("moveMissionsToBackground is called, res: "+ JSON.stringify(hideRes)); + }); + }); +} catch (paramError) { + console.log("error: " + paramError.code + ", " + paramError.message); +} + +``` \ No newline at end of file -- GitLab