#鸿蒙通关秘籍#如何在工程中实现延迟任务回调拓展能力?

HarmonyOS
1天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
星辰泪CPU

在工程的ets目录下新建目录,如WorkSchedulerExtension,在此目录内新建.ets文件,实现WorkSchedulerExtensionAbilityonWorkStartonWorkStop方法。接着在module.json5配置文件中注册WorkSchedulerExtensionAbility,设置type为“workScheduler”和配置相应的srcEntry。 javascript export default class MyWorkSchedulerExtensionAbility extends WorkSchedulerExtensionAbility { onWorkStart(workInfo) { console.info(onWorkStart, workInfo = ${JSON.stringify(workInfo)}); }

onWorkStop(workInfo) { console.info(onWorkStop, workInfo is ${JSON.stringify(workInfo)}); } }

{ "module": { "extensionAbilities": [ { "name": "MyWorkSchedulerExtensionAbility", "srcEntry": "./ets/WorkSchedulerExtension/WorkSchedulerExtension.ets", "label": "$string:WorkSchedulerExtensionAbility_label", "description": "$string:WorkSchedulerExtensionAbility_desc", "type": "workScheduler" } ] } }

分享
微博
QQ
微信
回复
1天前
相关问题
如何实现短时任务的申请和?
338浏览 • 1回复 待解决
WebView页面加载错误能力
824浏览 • 1回复 待解决