Home > Products > SophiaFramework UNIVERSE > Tutorial > Breakout > - 8 / 9 -

BREW Breakout - 8 / 9 -

Suspend and Resume

Suspend

Since BREW is a single thread environment, when other applications boots up, the current application will be suspended.

But timer events will be continued even when suspended. So do not forget to cancel the timer before suspending.

Anything that has to be done prior to suspension should be written in OnAppSuspend.

// Application suspend handler
Void Block::OnAppSuspend(AEESuspendReason reason,
AEESuspendInfoPtr info){...

// Codes during suspension
if (_status == APP_STATUS_PLAYING)
 {SFBShellSmp shell = SFBShell::GetInstance();shell->
CancelTimer(CBAnimate, (VoidPtr)this);if (_blockMotion)
{shell->CancelTimer(CBMoveBlocks, this);}}return;}

Both timers for animation and moving the blocks are canceled here.

Resume

Processes that should be executed after the application resumes from suspension, should be writen in OnAppResume.

In this game, the timers are canceled when being suspended. So they need to be started again.

Also, BREW and SophiaFramework UNIVERSE will not automatically redraw the screen when resuming, so it needs to be explicitly done.

This is the actual code:

// Application resume handler
Void Block::OnAppResume(AEEAppStartPtr environment)
{
  ...
  // Codes for resuming process
  switch (_status) {
    case APP_STATUS_PLAYING:
      DrawBlock();
      if (_blockMotion) {
        SFBShellSmp shell = SFBShell::GetInstance();
        shell->SetTimer(BLOCK_MOVEMENT_INTERVAL, CBMoveBlocks, this);
      }
      Animate();
      break;
    case APP_STATUS_READY:
      CreateStage(_nowStage);
      break;
    case APP_STATUS_WAIT_RESTART:
      Initialize();
      break;
    default:
      break;
  }

  return;
}

Finally, BREW Breakout is completed !

Go back  1   2   3   4   5   6   7   8   Apdx   Next page