We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
quickApp ReferencesQuick GameRuntime Quick GameLifecycle

Lifecycle

NOTE

Starting from version 1078, the API prefix has been changed from hbs to qg. The original prefix hbs is still supported.

Definition

Expand

API

Description

qg.exitApplication(Object object)

Exits the current quick game.

qg.getLaunchOptionsSync() (1103+)

Obtains the launch parameters of the quick game.

qg.onHide(function callback)

Listens for the event that a quick game is switched to the background.

qg.offHide(function callback)

Stops listening for the event that a quick game is switched to the background.

qg.onShow(function callback)

Listens for the event that a quick game is switched to the foreground.

qg.offShow(function callback)

Stops listening for the event that a quick game is switched to the foreground.

qg.exitApplication(Object object)

  • Description

    Exits the current quick game.

  • Parameters in object
    Expand

    Parameter

    Type

    Mandatory

    Description

    success

    function

    No

    Callback function triggered upon a successful API call.

    fail

    function

    No

    Callback function triggered upon a failed API call.

    complete

    function

    No

    Callback function triggered when the API call completes, regardless of success or failure.

  • Sample code
    qg.exitApplication({
            success : function () {
                    console.log("exitApplication success" );
            },
            fail:function(){
                    console.log("exitApplication fail");
            },
            complete:function() {
                    console.log("exitApplication complete");
            }
    });

qg.getLaunchOptionsSync() (1103+)

  • Description

    Obtains the launch parameters of the quick game.

  • Returns
    Expand

    Parameter

    Type

    Description

    query

    string

    Parameters carried for launching a quick game. For details, please refer to Parameters in query. The value can be converted into a JSON object.

    referrerInfo

    object

    Source information. If the quick game is launched from another quick game, AppGallery, Quick Game Center, or a home screen shortcut, this parameter is returned. Otherwise, {} is returned. For details, please refer to Parameters in referrerInfo.

    • Parameters in query
      NOTE

      The returned parameters depend on the parameters provided in the deep link. In addition to the following parameters, the custom parameters are also returned.

      Expand

      Parameter

      Type

      Description

      gameGiftId

      string

      Game gift package ID.

      giftUri

      string

      URL of the gift package page, which is the redirection URL set when you create the gift package. After the game is launched, the gift package page is displayed based on the gift package URL.

      userEntry

      string

      Channel platform. The options are as follows:

      • 101: Ocean Engine
      • 102: Tencent platform
      • 900999: custom channel platforms
    • Parameters in referrerInfo
      Expand

      Parameter

      Type

      Description

      type

      string

      Parameter source type.

      • shortcut: home screen icon
      • url: web page link
      • app: HarmonyOS app
      • quickapp: quick app or quick game
      • deeplink: link
      • other: other types

      extraData

      object

      For HarmonyOS apps, HarmonyOS games, quick apps, or quick games, packageName is used to identify the package name of the caller.

      {
         packageName:"com.huawei.appMarket"
      }

qg.onHide(function callback)

  • Description

    Listens for the event that a quick game is switched to the background.

  • Parameters
    Expand

    Parameter

    Type

    Mandatory

    Description

    callback

    function

    Yes

    Callback function triggered when a quick game is switched to the background.

  • Sample code
    qg.onHide(
         callback() {console.log("onHide");}
    );

qg.offHide(function callback)

  • Description

    Stops listening for the event that a quick game is switched to the background.

  • Parameters
    Expand

    Parameter

    Type

    Mandatory

    Description

    callback

    function

    Yes

    Callback function to be removed from the event listener.

  • Sample code
    qg.offHide(
         callback() {console.log("offHide");}
    );

qg.onShow(function callback)

  • Description

    Listens for the event that a quick game is switched to the foreground.

  • Parameters
    Expand

    Parameter

    Type

    Description

    query(1078+)

    object

    Query passed when the quick game is launched.

    referrerInfo(1078+)

    object

    Source information. If the quick game is launched from another quick game, AppGallery, Quick Game Center, or a home screen shortcut, this parameter is returned. Otherwise, {} is returned. For details, please refer to Parameters in referrerInfo.

    • Parameters in referrerInfo
      Expand

      Parameter

      Type

      Description

      type

      string

      Parameter source type.

      • shortcut: home screen icon
      • url: web page link
      • app: HarmonyOS app
      • quickapp: quick app or quick game
      • deeplink: link
      • other: other types

      extraData

      object

      For HarmonyOS apps, HarmonyOS games, quick apps, or quick games, packageName is used to identify the package name of the caller.

      {
      packageName:"com.huawei.appMarket"
      }
  • Sample code
    var callback = function (res) {
        console.log("onShow callback:\n" + JSON.stringify(res));
    };
    qg.onShow(callback);

qg.offShow(function callback)

  • Description

    Stops listening for the event that a quick game is switched to the foreground.

  • Parameters
    Expand

    Parameter

    Type

    Mandatory

    Description

    callback

    function

    Yes

    Callback function to be removed from the listener.

    NOTE

    The value of callback must be the same as that passed to onShow. Otherwise, the event listener cannot be canceled.

  • Sample code
    qg.offShow(
            callback() {console.log("offShow");}
    );
Search in References
Enter a keyword.