Foreground/Background state
When a mini game is launched and its API is displayed to the user, it is in the foreground state.
If the user taps the capsule button in the top right corner to close the mini game or presses the device's Home button to leave the host app, the mini game does not completely terminate but enters the background state, where it can continue running for a short period.
When the user re-enters the host app or reopens the mini game, it transitions from the background to the foreground. However, if the user does not return to the mini game for an extended period or if system resources are constrained, the mini game may be destroyed, meaning it is completely terminated.
Mini game launch
There are two types of mini game launches: cold launch and hot launch.
Cold launch: This occurs when the user opens the mini game for the first time or reopens it after it has been destroyed. The mini game needs to reload and start from scratch.
Hot launch: This occurs when the user has previously opened the mini game and reopens it within a certain period. The mini game has not been destroyed and simply transitions from the background to the foreground.
Mini game destruction timing
A mini game is typically destroyed under the following conditions:
Extended background state: If the mini game remains in the background for a certain period without returning to the foreground, it will be destroyed.
High system resource usage: If the mini game consumes too many system resources, it may be destroyed by the system or actively reclaimed by the host app.
iOS memory warnings: On iOS, if the host app receives consecutive system memory warnings within a certain interval, it may actively destroy the mini game and notify the user with a message like "Insufficient memory, please reopen the mini game." The specific strategy for this is continuously adjusted and optimized.
It is recommended that mini games use wx.onMemoryWarning to listen for memory warning events and perform necessary memory cleanup when needed.