FA模型啟動(dòng)Stage模型UIAbility
本文介紹FA模型的三種應(yīng)用組件如何啟動(dòng)Stage模型的UIAbility組件。
PageAbility啟動(dòng)UIAbility
在PageAbility中啟動(dòng)UIAbility和在PageAbility中啟動(dòng)PageAbility的方式完全相同。
開發(fā)前請(qǐng)熟悉鴻蒙開發(fā)指導(dǎo)文檔 :[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md
]
import featureAbility from '@ohos.ability.featureAbility';
import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
const TAG: string = 'PageInterflowFaAndStage';
const domain: number = 0xFF00;
@Entry
@Component
struct PageInterflowFaAndStage {
build() {
Column() {
//...
List({ initialIndex: 0 }) {
ListItem() {
Row() {
//...
}
.onClick(() = > {
let want: Want = {
bundleName: 'ohos.samples.etsclock',
abilityName: 'MainAbility'
};
featureAbility.startAbility({ want }).then((code) = > {
hilog.info(domain, TAG, 'Ability verify code: ' + JSON.stringify(code));
}).catch((error: BusinessError) = > {
hilog.error(domain, TAG, 'Ability failed: ' + JSON.stringify(error));
});
//...
})
}
//...
}
//...
}
//...
}
}
PageAbility訪問UIAbility(startAbilityForResult)
startAbilityForResult和startAbility的區(qū)別是當(dāng)UIAbility銷毀的時(shí)候會(huì)返回執(zhí)行結(jié)果。
在PageAbility中通過startAbilityForResult啟動(dòng)UIAbility和在PageAbility中通過startAbilityForResult啟動(dòng)PageAbility的方式完全相同。
import featureAbility from '@ohos.ability.featureAbility';
import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
const TAG: string = 'PageInterflowFaAndStage';
const domain: number = 0xFF00;
@Entry
@Component
struct PageInterflowFaAndStage {
build() {
Column() {
//...
List({ initialIndex: 0 }) {
ListItem() {
Row() {
//...
}
.onClick(() = > {
let want: Want = {
bundleName: 'ohos.samples.etsclock',
abilityName: 'MainAbility'
};
featureAbility.startAbilityForResult({ want }).then((result) = > {
hilog.info(domain, TAG, 'Ability verify result: ' + JSON.stringify(result));
}).catch((error: BusinessError) = > {
hilog.error(domain, TAG, 'Ability failed: ' + JSON.stringify(error));
});
})
}
//...
}
//...
}
//...
}
}
ServiceAbility/DataAbility啟動(dòng)UIAbility
在ServiceAbility/DataAbility中啟動(dòng)UIAbility和在ServiceAbility/DataAbility中啟動(dòng)PageAbility的方式完全相同。HarmonyOS與OpenHarmony鴻蒙文檔籽料:mau123789是v直接拿
import type common from '@ohos.app.ability.common';
import particleAbility from '@ohos.ability.particleAbility';
import type Want from '@ohos.app.ability.Want';
import type { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog';
const TAG: string = '[Sample_FAModelAbilityDevelop]';
const domain: number = 0xFF00;
class ServiceAbilityStartUiAbility {
onStart(): void {
// 啟動(dòng)UIAbility
let want: Want = {
bundleName: 'ohos.samples.etsclock',
abilityName: 'MainAbility'
};
particleAbility.startAbility({ want }).then(() = > {
hilog.info(domain, TAG, 'ServiceAbilityStartUIAbility Start Ability successfully.');
}).catch((error: BusinessError) = > {
hilog.info(domain, TAG, 'ServiceAbilityStartUIAbility Ability failed: ' + JSON.stringify(error));
});
}
};
export default new ServiceAbilityStartUiAbility();
審核編輯 黃宇
-
模型
+關(guān)注
關(guān)注
1文章
3112瀏覽量
48658 -
鴻蒙
+關(guān)注
關(guān)注
57文章
2302瀏覽量
42689
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論