HarmonyOS 后台任务没有调用回调方法

setBackgroundTask() {
  // 后台任务
  let wantAgentInfo: wantAgent.WantAgentInfo = {
    // 点击通知后,将要执行的动作列表
    wants: [
      {
        bundleName: "com.xxx.xxxworld",
        abilityName: "EntryAbility"
      }
    ],
    // 点击通知后,动作类型
    actionType: wantAgent.OperationType.START_ABILITY,
    // 使用者自定义的一个私有值
    requestCode: 0,
    // 点击通知后,动作执行属性
    wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
  };

  try {
    // 通过wantAgent模块下getWantAgent方法获取WantAgent对象
    wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj: WantAgent) => {
      try {
        backgroundTaskManager.startBackgroundRunning(this.context,
          backgroundTaskManager.BackgroundMode.LOCATION, wantAgentObj, callback)
      } catch (error) {
        console.error(`Operation startBackgroundRunning failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
      }
    });
  } catch (error) {
    console.error(`Operation getWantAgent failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.

为什么 这个后台任务没有调用 回调方法呢

HarmonyOS
2024-12-25 16:09:10
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect

因为后台没有实际任务,长时任务就是自动取消。请参长时任务参考:

https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/continuous-task-V5#%E7%BA%A6%E6%9D%9F%E4%B8%8E%E9%99%90%E5%88%B6

分享
微博
QQ
微信
回复
2024-12-25 17:38:44
相关问题
HarmonyOS 后台任务保持
1112浏览 • 1回复 待解决
HarmonyOS 咨询关于短时后台任务
749浏览 • 1回复 待解决
HarmonyOS 怎么清除entryAbility及后台任务
1146浏览 • 1回复 待解决
HarmonyOS 申请短时后台任务闪退
811浏览 • 1回复 待解决
智能穿戴如何启用后台任务?
3101浏览 • 1回复 待解决
HarmonyOS @Watch回方法没有改变
631浏览 • 1回复 待解决
HarmonyOS没有实现后台模糊的方法
799浏览 • 1回复 待解决