Skip to main content
Use this API to stop listening for background transition events that were registered with my.onAppHide().

Parameters

PropertyTypeRequiredDescription
callbackFunctionNoThe specific callback to remove. If omitted, all listeners are removed.

Code Example

Remove Specific Listener

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 Listeners

// Remove all onAppHide listeners
my.offAppHide();
Pass the same callback function reference to my.offAppHide() that was used with my.onAppHide() to remove only that specific listener.

my.onAppHide

Listen for background events

my.offAppShow

Stop listening for foreground events