Skip to main content
Senior
Feb 13, 2025 5:51 PM UTC
Solved

Changing screen programatically

Hi I was wondering what the best method is to change screens programatically. I saw

application().gotoXScreenNoTransition()

and also

static_cast<FrontendApplication*>(Application::getInstance())->gotoXScreenNoTransition(); 

Is there any difference in efficiency for the program?

This topic has been closed for replies.
GaetanGodart
GaetanGodartBest answer
ST Employee
Feb 17, 2025 12:35 PM UTC

Hello @Priyank ,

 

The 2 methods are similar in efficiency (technically slightly more efficient to go for application().gotoXScreenNoTransition() but this is very negligeable).

The difference is that the method application().gotoXScreenNoTransition() is simpler, more readable, and type-safe if application() returns the correct type directly.
On the other hand, static_cast<FrontendApplication*>(Application::getInstance())->gotoXScreenNoTransition() allows casting to a more specific type, which is useful if Application::getInstance() returns a base class pointer and you need to access derived class methods.

 

Regards,

Gaetan GodartSoftware engineer at ST (TouchGFX)

2 replies

GaetanGodart
GaetanGodartBest answer
ST Employee
Feb 17, 2025 12:35 PM UTC

Hello @Priyank ,

 

The 2 methods are similar in efficiency (technically slightly more efficient to go for application().gotoXScreenNoTransition() but this is very negligeable).

The difference is that the method application().gotoXScreenNoTransition() is simpler, more readable, and type-safe if application() returns the correct type directly.
On the other hand, static_cast<FrontendApplication*>(Application::getInstance())->gotoXScreenNoTransition() allows casting to a more specific type, which is useful if Application::getInstance() returns a base class pointer and you need to access derived class methods.

 

Regards,

Gaetan GodartSoftware engineer at ST (TouchGFX)
GaetanGodart
ST Employee
Feb 24, 2025 10:00 AM UTC

Hello @Priyank ,

 

Did you found the information you needed?

 

Regards,

Gaetan GodartSoftware engineer at ST (TouchGFX)