my.onAppHide().
Parameters
Code Example
Remove Specific Listener
Remove All Listeners
Related APIs
my.onAppHide
Listen for background events
my.offAppShow
Stop listening for foreground events
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Stop listening for events when the Mini Program switches to background.
my.onAppHide().
| Property | Type | Required | Description |
|---|---|---|---|
| callback | Function | No | The specific callback to remove. If omitted, all listeners are removed. |
Page({
onLoad() {
// Register listener
my.onAppHide(this.onAppHideHandler);
},
onUnload() {
// Remove specific listener
my.offAppHide(this.onAppHideHandler);
},
onAppHideHandler() {
console.log('App moved to background');
}
});
// Remove all onAppHide listeners
my.offAppHide();
my.offAppHide() that was used with my.onAppHide() to remove only that specific listener.