harmony 鸿蒙FA模型启动Stage模型UIAbility

  • 2022-12-13
  • 浏览 (730)

FA模型启动Stage模型UIAbility

本文介绍FA模型的三种应用组件如何启动Stage模型的UIAbility组件。

PageAbility启动UIAbility

在PageAbility中启动UIAbility和在PageAbility中启动PageAbility的方式完全相同。

import featureAbility from '@ohos.ability.featureAbility';
import { BusinessError } from '@ohos.base';

featureAbility.startAbility(
    {
        want: {
            bundleName: "com.ohos.stage",
            abilityName: "EntryAbility"
        }
    }
).then((code) => {
    console.info('Ability verify code: ' + JSON.stringify(code));
}).catch((error: BusinessError) => {
    console.error("Ability failed: " + JSON.stringify(error));
});

PageAbility访问UIAbility(startAbilityForResult)

startAbilityForResult和startAbility的区别是当UIAbility销毁的时候会返回执行结果。

在PageAbility中通过startAbilityForResult启动UIAbility和在PageAbility中通过startAbilityForResult启动PageAbility的方式完全相同。

import featureAbility from '@ohos.ability.featureAbility';
import { BusinessError } from '@ohos.base';

featureAbility.startAbilityForResult(
    {
        want: {
            bundleName: "com.ohos.stage",
            abilityName: "com.ohos.stage.EntryAbility"
        }
    }).then((result) => {
    console.info('Ability verify result: ' + JSON.stringify(result));
}).catch((error: BusinessError) => {
    console.error("Ability failed: " + JSON.stringify(error));
});

ServiceAbility/DataAbility启动UIAbility

在ServiceAbility/DataAbility中启动UIAbility和在ServiceAbility/DataAbility中启动PageAbility的方式完全相同。

import particleAbility from '@ohos.ability.particleAbility';
import { BusinessError } from '@ohos.base';

particleAbility.startAbility(
    {
        want: {
            bundleName: "com.ohos.stage",
            abilityName: "com.ohos.stage.EntryAbility"
        }
    }
).then(() => {
    console.info('Start Ability successfully.');
}).catch((error: BusinessError) => {
    console.error("Ability failed: " + JSON.stringify(error));
});

你可能感兴趣的鸿蒙文章

harmony 鸿蒙应用模型

harmony 鸿蒙使用显式Want启动应用组件

harmony 鸿蒙使用隐式Want打开网址

harmony 鸿蒙AbilityStage组件容器

harmony 鸿蒙访问DataAbility

harmony 鸿蒙FA模型访问Stage模型DataShareExtensionAbility

harmony 鸿蒙AccessibilityExtensionAbility

harmony 鸿蒙常见action与entities

harmony 鸿蒙API切换概述

harmony 鸿蒙app和deviceConfig的切换

0  赞