TGFX Class Life Cycles or How to change screens programmatically on startup?
Hi again,
I'm currently working on a TouchGFX project that requires me to have some one-time setup with some screens that are only shown to the user if the device is not yet set up, Let's call the first of these screens "WelcomeScreen" as opposed to the "MainScreen" for the sake of brevity.
So, if the device is set up, I want to show the MainScreen to the user, and if the setup procedure is not yet done, I want to show the WelcomeScreen to the user.
What I have tried now is
- add a method `bool isSetupComplete()` to the Model class.
- add invisible buttons that have dummy "Change Screen" interactions attached, and
- basically copy the code generated when adding a transition on a button in a view, i.e.
FrontendApplication& Model::application()
{
return *static_cast<FrontendApplication*>(touchgfx::Application::getInstance());
}and then add the following lines to the Model's c'tor:
if(setupIsComplete())
{
application().gotoMainScreenNoTransition();
}
else
{
application().gotoWelcomeScreenNoTransition();
}While testing for different return values of `isSetupComplete` I observed that it doesn't matter what it returned as the calls to gotoXXXScreenNoTransition() have no effect in the Model's c'tor.
Since I thought maybe Model construction occurs too early and the touchgfx::Application is not yet fully initialized at that point, I moved the "switching logic" into the WelcomeScreen's Presenter's `activate` method, which now looks like this:
void WelcomeScreenPresenter::activate()
{
if(model->isSetupComplete())
{
model->goToMainScreen();
}
}Again, no matter what `isSetupComplete` returns, the screen change does not occur. After the initial troubles, I can change screens programmatically with the method described above without any issues.
Am I missing something here? Is there a better way to change screens according to variables at runtime?
Best Regards,
Michael
