停止PageAbility

停止PageAbility通过featureAbility中的terminateSelf接口实现。

表1 featureAbility接口说明

接口名 接口描述
terminateSelf() 停止Ability。
terminateSelfWithResult(parameter: AbilityResult) 设置该PageAbility停止时返回给调用者的结果及数据并停止Ability。

如下示例展示了停止Ability的方法。

import featureAbility from '@ohos.ability.featureAbility';
import Logger from '../../utils/Logger';

const TAG: string = 'PagePageAbilityFirst';
(async (): Promise<void> => {
  try {
    Logger.info(TAG, 'Begin to terminateSelf');
    await featureAbility.terminateSelf();
    Logger.info(TAG, 'terminateSelf succeed');
  } catch (error) {
    Logger.error(TAG, 'terminateSelf failed with ' + error);
  }
})()