How to transfer data between apps using app designer

Hello,
I am working on APP1 which has a parameter x, I open APP2 by a button in APP1 and change x (which I already transfer to APP2 from APP1) in APP2.
How can I update x in APP1 when I close APP2 and come back to APP1?
I tried to put in APP2CloseRequest: APP1.x = app.x but seems it doesnt work
Thanks

3 件のコメント

Issa
Issa 2019 年 6 月 16 日
hello
how you passed x from app1 to app2?
Juan José Jiménez
Juan José Jiménez 2020 年 12 月 14 日
Hello, I have the same question, ho did you pass X from app1 to app2? I'm looking for this answer!
Leonor Vieira Dias
Leonor Vieira Dias 2021 年 2 月 10 日
Hello,
Could you explain how you got the data from the appA to go to the appB please?
Thanks

サインインしてコメントする。

回答 (2 件)

TADA
TADA 2019 年 6 月 16 日

2 投票

The simplest solution would be to couple the two apps. When you open app B send the object of app A to it. Then when app B updates x, it can update the property of app A.
A more robust solution would be to uncouple the two apps and add a mediator class. The mediator knows both app A and app B. It passes all the data between the two back and forth. Both apps don't need to know each other, only the mediator.
The reason I say this implementation is more robust is because tomorrow you may need app A to communicate with a third class instead of app B for some specific functionality. In that case you don't need to change app A, only the mediator class.

4 件のコメント

Nguyen Thuan
Nguyen Thuan 2020 年 8 月 3 日
@TADA: Hi TADA. Could you please explain how to make a mediator class for app designer?
If you have any app example, could you please share it?
Thanks a lot in advance.
Thuan Nguyen
TADA
TADA 2020 年 8 月 6 日
I attached a zip file with a very simple example
you have a main app which has axes and a button to open a dialogue for adding new x-y values
The dialogue has two spinners and two buttons OK and Cancel.
If you click OK the value pair from the spinners will be added to the plot
This is implemented using callbacks rather than return values from any of the methods
the AppMediator class knows how to show a new "dialogue" window, and has a callback function for when that window is done
App2 accepts the mediator in the startupFcn and then when one of the buttons is clicked it calls the callback function of the mediator and sends the spinners values.
The mediator accepts a callback function when the showDialogue function is called and it then calls this callback function when the dialogue sends an "OK" callback;
App1 also accepts the mediator in its startupFcn and in turn when its "add" button is clicked will call the mediators showValueDialogue function, it sends a function handle as a callback to the mediator
The last trick is that the mediator also accepts a function handle to generate the dialogue window in its Ctor, so that none of the classes really need to be coupled.
If I wanted to go decoupled all the way, I would make the AppMediator class implement some interface and then I would make the apps know that interface rather than the AppMediator implementation so that true decoupling of all the classes can be achieved.
Then, the only one whoes coupled to anything is my main script - startAppMediatorExample which creates the main app (app1) and the mediator and tells the mediator to use app2 as a dialogue.
Hopefully this clarrified the general idea
Noah Griffiths
Noah Griffiths 2021 年 7 月 27 日
Hi @TADA,
Wanted to thank you for this example and explanation as it promotes good coding practises. Global/properties sends shivers down my spine so when MATLAB's own documents recommends them I'm immedaitely searching for another solution. Thanks again!
TADA
TADA 2021 年 7 月 27 日
cheers Noah,
I know what you mean, globals give me an allergic reaction

サインインしてコメントする。

sam0037
sam0037 2016 年 6 月 23 日

1 投票

Hi,
You can use public properties as explained in the link below to share data between apps. And you can add a closeRequestFcn using the Callback button in the Editor tab of the APPDESIGNER window. Remember to add "delete(app)" in the closeRequestFcn or else the app wont close. I have attached a sample APP to illustrate the above. Run the SendData app which sends the data to RecvData app. Hope this helps.

3 件のコメント

Ho Nhu Y Nguyen
Ho Nhu Y Nguyen 2016 年 6 月 28 日
Thanks for your response.
But what I meant is there is a button on app A, it will open app B and send data to B (I already did this) then I will change the data in app B and app A will be updated when closing app B and coming back to app A (not opening a new A).
Wouter
Wouter 2017 年 4 月 5 日
Ho Nhu Y Nguyen did you already achieved this? I stubmle upon your topic now namely and am also wondering how to implement this behavior. Can you maybe share your findings if you have any?
Ho Nhu Y Nguyen
Ho Nhu Y Nguyen 2017 年 4 月 25 日
Hi Wouter, sorry I couldn't find the solution and currently not working on this.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeDevelop Apps Using App Designer についてさらに検索

質問済み:

2016 年 6 月 16 日

コメント済み:

2021 年 7 月 27 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by