lifecycleStateChange method

  1. @override
  2. @mustCallSuper
void lifecycleStateChange(
  1. AppLifecycleState state
)
inherited

This is the lifecycle state change hook; every time the game is resumed, paused or suspended, this is called.

The default implementation does nothing; override to use the hook. Check AppLifecycleState for details about the events received.

Implementation

@override
@mustCallSuper
void lifecycleStateChange(AppLifecycleState state) {
  switch (state) {
    case AppLifecycleState.resumed:
    case AppLifecycleState.inactive:
      if (_pausedBecauseBackgrounded) {
        resumeEngine();
      }
    case AppLifecycleState.paused:
    case AppLifecycleState.detached:
    case AppLifecycleState.hidden:
      if (pauseWhenBackgrounded && !paused) {
        pauseEngine();
        _pausedBecauseBackgrounded = true;
      }
  }
}