Coexisting with Android

Programmers in RFO-BASIC! must understand that their apps will be running on a processor that is doing many other things — such as maintaining contact with a WiFi or Bluetooth network or a cell tower — and may be running under battery power that the app should take care to conserve.

Conserving battery
Computing requires electric power; the BASIC program can use less power by spending more time in the PAUSE statement. Unfortunately, each execution of PAUSE is for a specific interval. The interval can be a variable or expression but it cannot adapt to things that happen during the interval. Moreover, PAUSE cannot be interrupted.

The REPEAT loops shown here are infinite. A well-behaved program needs a way, either in the main loop or through interrupts, for the user to make the program exit.  Longer pauses reduce battery use. A pause longer than a second (PAUSE 1000) may give the impression that the program has crashed. For programs without frequent user input, PAUSE 5000 may be best. The program's operations are inside a main loop with the following form:

REPEAT  PAUSE 5000 UNTIL 0 % That is, forever

Shorter pauses increase responsiveness to real-time events such as screen touches and key presses. If the main loop needs executing only every five seconds, the program can allow interrupts every 0.1 second by using a form like this:

REPEAT  FOR I = 1 TO 50 PAUSE 100 IF  THEN F_N.BREAK NEXT I UNTIL 0 % That is, forever

Battery usage depends on the ratio of time spent computing, to time spent pausing.

Gaming and measurement programs may require that the main loop execute at a constant rate. In this case, the PAUSE statement should deduct time spent in the main loop (but not specify a negative amount of time):

REPEAT InitialTime = CLOCK % Milliseconds since most recent start-up  PAUSE MIN(CLOCK - InitialTime, 1) UNTIL 0 % That is, forever