Minigame Runtime Mechanism
Minigames follow specific state-switching logic during the startup, running, and destruction processes.
Foreground and Background States
- Foreground state: after a minigame starts, the interface is displayed to the user.
- Background state: when the user taps the capsule button in the top-right corner to close the minigame, or presses the device Home key to leave the platform, the minigame does not fully terminate but instead enters the background state.
- Running restrictions: after entering the background, the minigame can keep running for a short period of time.
Startup Methods
Depending on whether the minigame has already been destroyed, startup falls into two cases:
| Startup Method | Definition and Description |
|---|---|
| Cold Start | The user opens it for the first time, or opens the minigame again after it has been destroyed. In this case it needs to be reloaded and started. |
| Hot Start | The user has already opened a minigame and opens it again within a certain period of time; the minigame moves from the background to the foreground. |
Destruction Timing
A minigame does not stay resident in memory indefinitely. It will be destroyed in the following cases:
- Long stay in the background: it remains unopened for a certain period after entering the background.
- System resource reclamation: when system memory is tight or the minigame occupies too many resources.
- iOS memory warning: on iOS, if system memory warnings are received continuously, the minigame will be proactively destroyed.
Optimization suggestion: developers should use sud.onMemoryWarning to listen for memory warning events and proactively perform memory cleanup when necessary.
Logic Rules for Reopening
There are two types of scenarios in which the user expects to open a minigame:
Scenario Classification
- Scenario A: opening the home page. The scene values are as follows:
| Scene Type | Description |
|---|---|
| 1 | Minigame main entry |
| 2 | Android system desktop icon |
| 3 | Returning from another minigame |
- Scenario B: opening a specific page designated by the minigame, with scene values other than those in Scenario A The logic for reopening a minigame is as follows:
| Previous Scenario | Current Opening Scenario | Final Behavior |
|---|---|---|
| Scenario A | Scenario A | Retain the original state (continue from last progress) |
| Scenario B | Scenario A | Clear the page stack and reopen the home page (reStart) |
| Scenario A or B | Scenario B | Clear the page stack and open the specified page (reStart) |
