cancel
Showing results for 
Search instead for 
Did you mean: 

Passing data from one screen to another

GMeur
Senior

Hello,

What's the best way, if any, to pass data from one screen to another if you don't want to save this data anywhere BUT in the screen classes themselves?

I can't think of a way to do that. I know that the data can be easily saved in the application or model class and then retrieve at will but it's not what I'm looking for.

Thanks in advance.

1 REPLY 1
Martin KJELDSEN
Chief III

Hi @GMeur​,

In touchgfx, only one View/Presenter pair is active at any point in time. So you cannot pass data from screen to screen directly. When a screen is activated the activate() method of the associated presenter is called to configure the view, and then setupScreen() of the view is called to initialize the gui state of the screen.

Here, in your presenter, you would then load the data from the model that you need to present. That's the way to "pass data" between screens.

View1 -> Presenter -> Model -> Presenter -> View2.

You have a model pointer in your presenter (called model) and you have a presenter pointer in your view (called presenter).

void MyView1::doSomething()
{
    presenter->storeValue(value);
}
 
void MyPresenter1::storeValues(uint8_t _val)
{
    model->store(MY_VIEW1, _val);
}

Then...

void MyPresenter2:activate()
{
    view->initValue(model->getValue(MY_VIEW1));
}
 
void MyView2::initValue(uint8_t _val)
{
     //Present values in e.g. a textarea 
}

/Martin