#鸿蒙通关秘籍#如何创建和启动一个ServiceAbility?

HarmonyOS
2024-12-11 15:06:25
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
LogicLynx

在DevEco Studio中创建ServiceAbility,系统将生成onStartonStop等生命周期方法。接下来,通过featureAbility中的startAbility接口启动ServiceAbility,如下所示: javascript import featureAbility from '@ohos.ability.featureAbility'; import Want from '@ohos.app.ability.Want';

const startServiceAbility = async () => { let want = { bundleName: 'com.samples.famodelabilitydevelop', abilityName: 'com.samples.famodelabilitydevelop.ServiceAbility' }; await featureAbility.startAbility({ want }); }

在代码执行时,startAbility()方法将负责启动对应的ServiceAbility。

分享
微博
QQ
微信
回复
2024-12-11 17:27:47
相关问题