We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Routine called when Application Quits
Page Index Toggle Pages: 1
Routine called when Application Quits? (Read 763 times)
Routine called when Application Quits?
Apr 3rd, 2007, 1:16am
 
Dear all,

I'm sorry if this has been covered, but I couldn't find it anywhere.

Is there any routine that is called when you quit a processing app, using com+Q, alt+F4 or the menu?

If there is none, can someone guide me to where I can find some information about creating one?

Thanks in advance!

Best regards,

Rui
Re: Routine called when Application Quits?
Reply #1 - Apr 3rd, 2007, 12:50pm
 
try:
Code:
public void stop() { 

... things you want to do on exit ...

//add this so processing's own quit code is run too.
super.stop();
}
Re: Routine called when Application Quits?
Reply #2 - Apr 3rd, 2007, 1:41pm
 
Hi!

I've already tried that and unfortunately it doesn't work... thanks anyway!

I have an app that uses a processing standalone as an interface and a hidden Max/MSP standalone as audio engine. They communicate with each other via OSC. I've added a button to shut down, that sends a "shut-down" command to the max engine before an exit() in Processing.

The problem is that most people quit the application with command+Q or the menu and that leaves the max engine running on background, consuming resources and preventing the application bundle to come up again.

I really want to keep it simple for the user, as this program is aimed mostly at kids and is being offered for unattended use and soon as a free download...

Best regards,

Rui
Re: Routine called when Application Quits?
Reply #3 - Apr 3rd, 2007, 3:44pm
 
Code:

import processing.opengl.*;

ShutDownListener sdl;

void setup () {
println( "setup" );
size( 200, 200 );
if ( frame != null )
{
sdl = new ShutDownListener(this);
frame.addWindowListener( sdl );
}
}

void draw () {
}

public void stop () {
println( "stop" );
super.stop();
}

public void destroy () {
println( "destroy" );
super.destroy();
}

public void exit () {
println( "exit" );
super.exit();
}


public class ShutDownListener
implements WindowListener
{
ShutDownListener ( PApplet _p )
{
_p.registerDispose( this );
}

void dispose () {
println( "ShutDownListener: dispose" );
}

void windowClosing(WindowEvent e) {
println( "ShutDownListener: window closing" );
}

void windowActivated(WindowEvent e) {
}
void windowClosed(WindowEvent e) {
}
void windowDeactivated(WindowEvent e) {
}
void windowDeiconified(WindowEvent e) {
}
void windowIconified(WindowEvent e) {
}
void windowOpened(WindowEvent e) {
}
}


i know this will not run anything when you quit via keyboard or menu on os-x. for that you will have to implement ApplicationListener (i guess). not sure how it behaves on windows / linux.

another idea would be to start another app / deamon that checks if both apps are still runnning and then shuts one down if the other was quit.

F
Re: Routine called when Application Quits?
Reply #4 - Apr 3rd, 2007, 7:26pm
 
> another idea would be to start another app / deamon that checks if both apps
> are still runnning and then shuts one down if the other was quit.

Excellent idea! Thanks...

It's really easy to implement and guarantees that if either part of the program crashes, the other will "crash" as well... why didn't I think of that?!

I wonder what would happen if the babysitter app crashes, though... Smiley

Best regards,

Rui
Re: Routine called when Application Quits?
Reply #5 - Apr 3rd, 2007, 7:41pm
 
ruipenha wrote on Apr 3rd, 2007, 7:26pm:
I wonder what would happen if the babysitter app crashes, though... Smiley


well, all apps could be watching each other .. but that'd be really paranoid Smiley

F
Page Index Toggle Pages: 1