One method of accomplishing this is detailed below:
Step 1)
Create a property for "appA" to which you will assign the object instantiated when you call "appB". For example, let "appBHandle" be the property name. For now, initialize it as an empty array. You can adapt the following example code:
properties (Access = private)
appBHandle = [];
end
Step 2)
In the Callback Function for the Push Button, check if "appBHandle" is either...
a) empty, which is true the first time the Push Button is pressed
b) an invalid handle, which is true when the Push Button is pressed after the object has been deleted (i.e. after "appB" has been closed)
If so, then call the function "appB" (to open the App and its associated UI Figure), and assign the object that is instantiated to the variable/property "appBHandle".
If not, then "appBHandle" can be utilized to bring "appB" to the foreground of your screen. This is done by toggling the visibility property of the UI Figure for "appB" off and then immediately back on.
You can adapt the following example code into the Callback Function for your Push Button:
function ButtonPushed(app, event)
if isempty(app.appBHandle) || ~isvalid(app.appBHandle)
app.appBHandle = appB;
else
app.appBHandle.UIFigure.Visible = 'off';
app.appBHandle.UIFigure.Visible = 'on';
end
end
Best Answer