从最新日志确认了问题的根本原因:
global listener received state updateWidget未注册到GlobalWidgetManager
updateAllWidgetsWithData 被调用,但 activeWidgets.size = 0formProvider.updateForm 调用Widget生命周期问题:
文件: entry/src/main/ets/entryformability/EntryFormAbility.ets
// onFormEvent中添加widget注册检查
onFormEvent(formId: string, message: string): void {
// 确保widget已注册到GlobalWidgetManager
if (!this.globalWidgetManager.hasWidget(formId)) {
this.globalWidgetManager.registerWidget(formId, 'large' as WidgetSize);
}
// ... 其他逻辑
}
// onUpdateForm中添加widget注册检查
onUpdateForm(formId: string): void {
// 确保widget已注册到GlobalWidgetManager
if (!this.globalWidgetManager.hasWidget(formId)) {
this.globalWidgetManager.registerWidget(formId, 'large' as WidgetSize);
}
// ... 其他逻辑
}
添加详细的widget状态日志:
修复后的完整数据流:
修复后应该能看到以下日志序列:
Heanup EntryFormAbility onFormEvent called: 678330255
Heanup EntryFormAbility widget 678330255 not registered, registering as LARGE size
Heanup EntryFormAbility global listener received state update: isPlaying=true
Heanup EntryFormAbility updateAllWidgetsWithData called with isPlaying=true
Heanup EntryFormAbility active widgets count: 1
Heanup EntryFormAbility found active widget: 678330255, size: large
Heanup EntryFormAbility updating widget: 678330255
Heanup widget 678330255 calling formProvider.updateForm with isPlaying=true
Heanup widget 678330255 updated successfully: isPlaying=true
这个修复应该能彻底解决widget无法更新的问题,确保在任何生命周期情况下widget都能正确注册和更新。