Applications

From NewBASIC's point of view, an application is a program module. A program module roughly corresponds to the file that results when you use the Builder's build option.

A module may load another module. Not all modules have been set up to act as applications. What makes an application module special? From a programming point of view, there's nothing special. The Program Launcher application needs to know about the application module. How exactly it will manage this, depends upon who wrote the Program Launcher.

Application Life Cycle

Between the time it is loaded and unloaded an application will go through the following stages:

  1. The application module is loaded into memory. The application module's module_init() routine is called.
  2. The Program Launcher program calls the application module's module_goTo() routine--specifying what "context" the application should start in. The Program Launcher calls the application module's module_show() routine--this routine is responsible for bringing up the module's starting UI (user interface).
  3. If the user decides to start using some other application, then the Program Launcher will tell the application module to hide its windows, calling the module_hide() routine. If the user switches back to your application, the Program Launcher will call the application module's module_show() routine.
  4. At some point, the Program Launcher may need to shut the application down: perhaps the user hasn't used the application in a while and the device needs the memory; perhaps the user has pressed the power button and all applications must shut down. The Program Launcher program calls the application's module_getContext() routine. This routine should return a "context" string. (The Program Launcher will store this context string away; the next time the Program Launcher loads the application, it will pass this string to the module_goTo() routine.) The application module's module_exit() routine will be called last, giving the program a chance to release any resources it may have grabbed.

Context

When the Program Launcher is about to unload an application, it will call that application's module_getContext() routine to get a text string. When the Program Launcher loads the application, it will call the application's module_goTo() routine, passing that text string. (When the application is loaded for the very first time, the Program Launcher will pass the empty string to module_goTo().)

There is no set API (application programming interface) for context strings; it need make sense only to your program. The program uses the string so that it may, when loaded, restore itself to its previous state when it was shut down.

Preventing Unloading

When the device is running out of free memory, the Program Launcher might unload a hidden (non-active) application to free up its memory. If an application computes even while hidden, it wishes to avoid being unloaded as long as possible. To do this, the application module should define and export an integer variable called preventUnload and set it non-zero. For more information, see See preventUnload .