# Mini Program Operating Mechanisms

# Starting Mini Programs

Mini Programs can be started in two ways: "cold startup" and "hot startup".

  • Hot startup: This is the process of switching a Mini Program running in the background to the foreground when a user wants to re-open the opened Mini Program after a certain period of time.
  • Cold startup: This occurs when a user opens a Mini Program for the first time or re-opens it after its termination by Weixin.

The restart concept is not applicable to Mini Programs.

# Foreground/Background Status

When a user taps the Mini Program control button in the upper right corner to close a Mini Program or presses the Home button on the mobile to leave Weixin, the Mini Program is not terminated but runs in the background.

When the user re-opens Weixin or the Mini Program, the Mini Program will return from the background to the foreground.

# Terminating Mini Programs

Note: A Mini Program is terminated only after it runs in the background for a certain period of time or it occupies too much system resources.

  • When a Mini Program is in the background, it will run for five minutes. After that, Weixin will terminate it.
  • When a Mini Program occupies too much system resources, it may be terminated by the system or the Weixin app.
    • In iOS, a Mini Program is terminated when the Weixin app receives two or more consecutive memory consumption alerts within five seconds. The user will see the prompt "This Mini Program was terminated because it slowed down Weixin".
    • We recommend that Mini Programs listen on memory alert events via wx.onMemoryWarning to free up memory when necessary.

For Mini Programs with a base library version of 1.1.0 or higher, but lower than 1.4.0: When the user enters the Mini Program from entries such as Scan or Forward (with scene values of 1007, 1008, 1011 and 1025) and exits the Mini Program when it is not sticky on top, the Mini Program will be terminated.

# Re-open Logic

Start from base library version 1.4.0. Please remaining backward compatible.

Users may open a Mini Program in the following two scenarios:

A. Open homepage: Available scene values include:

Scene Value ID Description
1001 The main Mini Program entry in Discover, "Recently Used" list
1019 Weixin Wallet
1022 The entry of a Mini Program sticky on top of the chat window
1023 Android desktop icon
1038 Returned from another Mini Program
1056 Music player menu

B. Open a page specified by the Mini Program: the scene value can be any other value than A.

The logic for re-opening a Mini Program is as follows:

Previous Scene Current Scene Effect
A A Remain as it is
B A Clear the previous page stack and open the homepage (execute wx.reLaunch to go to the homepage)
A or B B Clear the previous page stack and open a specified page (execute wx.reLaunch to go to the specified page)