background image
C H A P T E R 1 7
Additional System Services
Using Additional System Services
The following code example removes all alarms an application has scheduled for
the next five minutes:
foreach alarmKey in GetAppAlarmKeys(":MyApp:MySig") do
if not (GetAlarm(alarmKey).time > Time() + 5) then
RemoveAlarm (alarmKey);
Removing Installed Alarms
The functions
remove a particular alarm
and all of an application's alarms, respectively. The
function takes
the alarm key of the alarm to remove as its single argument. Use of this function is
demonstrated in the code example in "Retrieving Alarm Keys" beginning on
page 17-12.
function takes an alarm key suffix as an argument and
removes all alarms whose key ends with this suffix. For this reason it is important
for all alarms created by a particular application to use alarm keys ending with the
same suffix. If your application's alarm are not meaningful if your application is
not installed, you should call this function in your application's
Common Problems With Alarms
This section describes common problems encountered with use of the alarm service.
Problems With Alarm Callback Functions
Alarms are kept in a soup; thus, they persist across restarts and installation or
removal of packages. This means that the arguments you pass to your callback
function are also stored in a soup; hence, these arguments are also copied deeply.
(See the description of the
function in Newton Programmer's
Reference.) Therefore, you must avoid indirectly referencing large objects lest
they unnecessarily inflate the size of your entries in the alarm soup.
A classic example of accidentally referencing a large object is in dynamically
creating the function object executed with the alarm. Function objects may contain
references to the lexical environment and the current receiver (
) at the time
they are created. For example, function objects created from a view method reference
the root view through their parent chain. If you pass such a function object to the
function, the system attempts to copy the entire root view into the
alarm soup. One way to minimize the size of your callback function object is to
pass as your callback a one-line function that invokes a method in your application
package to actually do the work.
© 2007-2024, o7 studio » при воспроизведении материала сайта ссылка обязательна