Skip to main content
Senior
February 13, 2025
Solved

Changing screen programatically

  • February 13, 2025
  • 2 replies
  • 414 views

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?

Best answer by GaetanGodart

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,

2 replies

GaetanGodart
GaetanGodartBest answer
Technical Moderator
February 17, 2025

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,

GaetanGodart
Technical Moderator
February 24, 2025

Hello @Priyank ,

 

Did you found the information you needed?

 

Regards,