my.onAppShow

Listen for the event that the mini program is switched to foreground from background. The triggered time of the API is the same with that of the onShow() method. To unlisten for the event that the mini program is switched to background from foreground, see my.offAppShow.

Sample code

.axml

copy
<!-- .axml-->
<button size="default" onTap="offAppShowHanlder" type="primary">Unlisten for the event that the mini program is switched to foreground from background</button>

.js

copy
//.js
onLoad() {
    my.onAppShow(this.onAppShowHandler)
},
//The method of listening for the event that the mini program is switched to foreground from background
onAppShowHandler() {
    console.log('The mini program is switched to foreground from background')
},
//The method of unlistening for the event that the mini program is switched to foreground from background
offAppShowHanlder() {
    my.offAppShow(this.onAppShowHandler)
},
apphide() {
    console.log('The mini program is switched to background from foreground')
}

Parameters

The parameter is in object type and has the following property:

Property

Type

Description

callback

Function

The callback function for the event that the mini program is switched to foreground from background. For more information about the callback parameters, see the onShow() method.