啟動(dòng)本地PageAbility
PageAbility相關(guān)的能力通過featureAbility提供,啟動(dòng)本地Ability通過featureAbility中的startAbility接口實(shí)現(xiàn)。
表1 featureAbility接口說明
接口名 | 接口描述 |
---|---|
startAbility(parameter: StartAbilityParameter) | 啟動(dòng)Ability。 |
startAbilityForResult(parameter: StartAbilityParameter) | 啟動(dòng)Ability,并在該Ability被銷毀時(shí)返回執(zhí)行結(jié)果。開發(fā)前請(qǐng)熟悉鴻蒙開發(fā)指導(dǎo)文檔:[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md ]。 |
如下示例通過startAbility顯式啟動(dòng)PageAbility。啟動(dòng)Ability的參數(shù)包含want,關(guān)于want的說明詳見[對(duì)象間信息傳遞載體Want],相應(yīng)的,隱式啟動(dòng)與顯式啟動(dòng)也不在此贅述。
import featureAbility from '@ohos.ability.featureAbility';
import Want from '@ohos.app.ability.Want';
import hilog from '@ohos.hilog';
const TAG: string = 'PagePageAbilityFirst';
const domain: number = 0xFF00;
(async (): Promise< void > = > {
try {
hilog.info(domain, TAG, 'Begin to start ability');
let want: Want = {
bundleName: 'com.samples.famodelabilitydevelop',
moduleName: 'entry',
abilityName: 'com.samples.famodelabilitydevelop.PageAbilitySingleton'
};
await featureAbility.startAbility({ want: want });
hilog.info(domain, TAG, `Start ability succeed`);
}
catch (error) {
hilog.error(domain, TAG, 'Start ability failed with ' + error);
}
})()
審核編輯 黃宇
-
鴻蒙
+關(guān)注
關(guān)注
57文章
2339瀏覽量
42805
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論