Resources | Resources |



Application cleanup and shutdown

On a Brew MP device, a variety of scenarios can lead to an application closing. Some of these scenarios are voluntary and application driven, such as handling user input and determining that it is time to close. Other scenarios include requests to shutdown from other applications, or being forced to shutdown from a system service, such as the Brew MP memory handler.

Whatever the reason for an application being closed, there are some important things to keep in mind when handling termination events. During the closing process, an application may have many objects to call, clean-up, and release. Likewise, there may be system services that have handles pointing back into application objects, and these need to be cleaned up too.

Fortunately Brew MP is designed to help in this cleanup process. This section describes how to handle object cleanup in the following shutdown scenarios, for both windowed and non-windowed applications:

  • Application initiated shutdown

    Applications may decide that it is time to close. The user may have pressed a Close button on the screen, or the application may have successfully completed its work. To close, both windowed and non-windowed applications should call IShell_CloseApplet(). At the highest level, this is the only difference between a self-shutdown, and a third-party or forced shutdown, as both trigger the final shutdown process (described below).

    Windowed applications should close their windows and release all window resources before calling IShell_CloseApplet(). Applications should close windows by calling IWindowMgr_CloseWindow() , and waiting for the window event handler to receive the WM_STATUS_CLOSE. For detailed information on closing windows and windowed applications, see the Window Manager Technology Guide in on the Brew MP web site.

  • Receiving the EVT_APP_STOP event

    An application receives the EVT_APP_STOP event either as a result of initiating shutdown, or when a service makes the same call. To handle this event, an application should perform final shutdown steps described below and set *dwParam to TRUE, which indicates to Brew MP that the application is ready to be shutdown, and any system-held resources for that application can be released.

Final shutdown

To prepare for Brew MP to unload the application, the application needs to perform any application cleanup not included the application's FreeAppData() function; the additional clean up may include writing final log file messages, saving settings changes, or writing other data to files. Soon after the application has finished its cleanup and returns from the EVT_APP_STOP event, the AEEApplet's pFreeAppData function is called, and the application's AEEApplet structure is released by Brew MP. At this point, the application is no longer running and has been completely released.