How to catch SCREEN_UNLOADED event after exit a temporary screen

What do you want to achieve?

I dont know if this is a Bug or I’m doing something wrong.
I have a temporary screen and I want to call a function when the screen is deleted so I added callbacks to SCREEN_UNLOADED and SCREEN_UNLOAD_START but only SCREEN_UNLOAD_START seems to be working.

What have you tried so far?

These are my screen events:

This is generated ui.c:

This is generated events.c:

Only Home screen unload start is printed on the console.


  • SquareLine Studio version: v1.4.1. LVGL v8.3.6
  • Operating system:
  • Target hardware:

You’re not doing anything wrong and it’s not an unexpected behaviour either. It’s a combination of the temporary screen behaviour dictated by SquareLine Studio and the callback behaviour of LVGL. When you switch from a temporary screen to other screen, the scr_unloaded_delete_cb function in ui_helpers.c activated by the first SCREEN_UNLOADED trigger (registered by the screen-init function) deletes it (and makes its pointer NULL) when you switch to other screen. Then LVGL simply doesn’t perform the next SCREEN_UNLOADED callback (registered later by you) on the already deleted screen object.
If you really want to add some operations to the SCREEN_UNLOADED event of a temporary screen (because SCREEN_UNLOAD_START doesn’t suffice), currently you can only do it by moving the temporary screen unload event (added by SquareLine Studio) in the screen-init function after the other exported callbacks (the end of the function). We’ll discuss it to do the export in SquareLine Studio like this by default, seems more logical and an improvement considering this use-case. Thanks for reporting this.

1 Like