I wrote a small test widget app to get acquainted with the "activity completed event" processing.
In the main app class I have
function getInitialView() as Array<Views or InputDelegates>? { if (System has :ServiceDelegate) { Background.registerForActivityCompletedEvent(); } return [new TestAppView()] as Array<Views or InputDelegates>; } function onBackgroundData(flag as PersistableType) as Void { if (flag) { System.println("Activity completed!"); } } function getServiceDelegate() as Array<ServiceDelegate> { return [new BackgroundDelegate()] as Array<ServiceDelegate>; }
and in the BackgroundDelegate class I have
function onActivityCompleted(activity as { :sport as Sport, :subSport as SubSport }) as Void { Background.exit(true); }
Then I ran the app in the simulator and clicked "Simulation -> Background Events -> Activity Completed Event" and got "Activity completed!" in the debug console which signifies that the code is written correctly.
But then I hoped to get the same message in the debug console in case I finish the activity using the "Simulation -> Activity Data" functionality. I started the activity playback, then clicked the "Start" button, then the "Stop" button, and finally the "Save" button. But nothing happened, the console was empty. Tried Edge 1030 and Fenix 7 devices in the simulator, behavior for both is the same.
So is it just incorrect/insufficient handling of the "Save" button in the simulator and will the onActivityCompleted() be invoked in the background widget process on the real device?