How to exit back to launcher?
How do I make my program exit back to the Launcher?
One way to do this is to call SysUIAppSwitch(). This just sets the operating system's global "next app" variable to the Launcher and adds an appStopEvent to your app's event queue. This won't exit your program immediately; it just gracefully mimics the user tapping on their Palm's Launcher soft button.
This method has a small drawback, though. Suppose that your application has an "Exit" button and you want to exit back to the Launcher when this button is tapped. Since, when using the above method, you are essentially stuffing a tap in the event queue, those Palm models that emit a click on every tap will emit two clicks - once because you tapped on the Exit button and a second time because the system thinks that you have made the tap that stuffed the event in the event queue. If you find this annoying, use the method below.
A more immediate way to exit your program is to use ErrThrow and ErrCatch. Put an ErrCatch clause in your PilotMain and call ErrThrow to jump to pop out to the nearest catch block. Assuming there are no other catch clauses between the throw and the one in PilotMain, this will pop you clear out to PilotMain. When you return from PilotMain, your program will end. The Palm OS Companion PDF file covers this in chapter 15.
Unfortunately, the Palm OS Companion basically just lists the syntax with these functions without a good example of how to use them for this particular purpose. If you are new to Palm programming and have never used them before, this could be a bit frustrating. Here is an example how to use them in your application in order to process an Exit button and an Exit menu item:
static Boolean MainFormHandleEvent (EventPtr eventP)
{
switch (eventP->eType)
{
case menuEvent:
if (eventP->data.menu.itemID == MenuExit)
ErrThrow (0L);
else
return MainFormDoCommand (eventP->data.menu.itemID);
break;
case ctlSelectEvent:
switch (eventP->data.ctlSelect.controlID)
{
case ButtonExit:
ErrThrow (0L);
:
:
default:
break;
}
break;
:
:
default:
break;
}
return handled;
}
static UInt32 YourProgPalmMain (UInt16 cmd, MemPtr /*cmdPBP*/, UInt16 launchFlags)
{
Err error;
switch (cmd)
{
case sysAppLaunchCmdNormalLaunch:
error = RomVersionCompatible (ourMinVersion, launchFlags);
if (error)
return (error);
ErrTry
{
error = AppStart ();
if (error)
return error;
FrmGotoForm (YourProgForm);
AppEventLoop ();
}
ErrCatch (inErr)
{
}
ErrEndCatch;
AppStop ();
break;
default:
break;
}
return 0;
}
UInt32 PilotMain (UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags)
{
return YourProgPalmMain (cmd, cmdPBP, launchFlags);
}