Switching screens

Description

Hi
How to switch screens properly in if-else conditions
I want to switch screens based on the value in if-else condition
For example:
If the value is 1 I want change screen to test_screen1(); else change the screen to test_screen2();
When I try to change the screen the screen not displaying properly (some times unknown objects are creating at top left, some times the created objects are not showing on screen but when I touch on object created area the object is coming).
I am just calling screen functions. Did I missed anything while switching the screens?
And when I switch screens normally (changing screens on button click it works good)

Thanks in Advance.

What MCU/Processor/Board and compiler are you using?

ARM

What LVGL version are you using?

7.11.0

What do you want to achieve?

What have you tried so far?

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

/*You code here*/

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

Hello
It would be helpful if you can show code examples of what is working and is not working. Ideally just the minimum to show the differences between the two.

Also a switch/case statement is better and more efficient compared to if else statements.

Well this is my idea: you create a container and create the screen 1 into it and then if you want to change to the second screen just clean the container and redraw the second screen.

Hi there,

I’m not sure if this is the proper solution but what I do at the moment is the following in order to load new screens:

lv_obj_clean(lv_scr_act());
lv_obj_t * screen;
screen = lv_obj_create(NULL, NULL);
lv_scr_load(screen);
lv_indev_wait_release(lv_indev_get_act());
lv_obj_t * cont = lv_cont_create(screen, NULL);

not displaying properly sounds like you forget to clean the screen

Hi Rouvo, thanks for the reply.
I have a doubt. I have 2 screens on which screen should I write these lines? And is container object is mandatory?
I am not using containers in my screens. I am directly creating objects.

Thanks.

hmm… I create 2 containers for 2 screens then load them as needed. :thinking: