Operation Mechanism
Foreground/background state
After the mini-game is started, the interface is displayed to the user, and the mini-game is in the foreground state.
When the user clicks the capsule button in the upper right corner to close the mini-game, or presses the device Home button to leave the host app, the mini-game does not completely terminate, but enters the background state, and the mini-game can still run for a short time.
When the user enters the host app again or opens the mini-game again, the mini-game will enter the foreground from the background. However, if the user has not entered the mini-game for a long time, or the system resources are tight, the mini-game may be destroyed, that is, it will completely terminate.
Mini-game startup
Mini-game startup can be divided into two situations, one is cold start and the other is hot start.
Cold start: If the user opens the mini-game for the first time, or the mini-game is opened again by the user after being destroyed, the mini-game needs to be reloaded and started, that is, cold start.
Hot start: If the user has opened a mini-game and then opens it again within a certain period of time, the mini-game is not destroyed at this time, but only enters the foreground state from the background state. This process is hot start.
Mini-game destruction time
Usually, the mini-game will only be destroyed when it enters the background for a certain period of time or the system resources are too high. Specifically, it includes the following situations:
- When the mini-game enters the background, it can maintain a short period of operation. If it does not enter the foreground during this period, the mini-game will be destroyed.
- When the mini-game occupies too many system resources, it may be destroyed by the system or actively recycled by the host App.
- On iOS, when the host app receives system memory warnings continuously within a certain time interval, it will actively destroy the mini-game according to a certain strategy, and prompt the user that the running memory is insufficient, please reopen the mini-game. The specific strategy will continue to be adjusted and optimized.
- It is recommended that mini-games usewx.onMemoryWarning to monitor memory warning events when necessary and perform necessary memory cleanup.