目录

What Can I Do If Vibration Occurs During Scene Switching After a User Swipes Up to Exit the Game?

Perform the following steps:

  1. Define the global variable isCacheStatus using globalThis. In the onCreate function, set isCacheStatus to false. If the isLaunchMirrorEnabled API returns true, update the value to true.

  2. Add the isCacheStatus check before the startVibration function. If the current state is cache, the vibration operation is not performed.

The following uses a Tuanjie project as an example.

// TuanjiePlayerAbilityBase.ets
import { launchAcceleration } from '@kit.GraphicsAccelerateKit';
onCreate(): void {
  globalThis.isCacheStatus = false;
  // ......
}
onWindowStageWillDestroy(): void {
  if (launchAcceleration.isLaunchMirrorEnabled()) {
    globalThis.isCacheStatus = true;
    // ......
  }
}

// TuanjieVibrate.ets
static vibrate(vibrateMs: number) {
  if (globalThis.isCacheStatus) {
    console.info('globalThis.isCacheStatus true, vibration returned.');
    return;
  }
  // ......
}