my.onAppHide

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

Sample code

.axml

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

.js

copy
//.js
onLoad() {
    my.onAppHide(this.onAppHideHandler)
},
// The method of listening for the event that the mini program is switched to background
onAppHideHandler() {
    console.log('The method of listening for the event that the mini program is switched to background')
},
// The method of unlistening for the event that the mini program is switched to background
offAppHideHanlder() {
    my.offAppHide(this.onAppHideHandler)
},

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 background.