HarmonyOS应用开发-Page Ability启动Service Ability

鸿蒙时代
发布于 2021-11-3 10:09
浏览
0收藏

Page Ablity响应交互,从而调用Service Ability是鸿蒙开发中最常用的交互方式,在Page Ablity使用startAbility(intent)启动Service Ability,Service Ability端在onCommend做出响应。
Page Ablity:

Operation operation = new Intent.OperationBuilder()
        .withDeviceId("")
        .withBundleName("mytest.app")
        .withAbilityName("com.example.album.Ability.service.PlayServiceAbility")
        .build();
intent.setOperation(operation);
intent.setParam("item",item);
// 启动Service
context.startAbility(intent,0);

Service Ability

protected void onCommand(Intent intent, boolean restart, int startId) {
    super.onCommand(intent, restart, startId);
    HiLog.info(TAG, "发布公共事件");
    //这里写响应内容
  
}

本文主要根据官方文档学习体验整理

分类
标签
HarmonyOS应用开发-Page Ability启动.docx 13.78K 14次下载
1
收藏
回复
举报
回复
    相关推荐