Listen for back press events
By listening for back press events, the super app can capture the user's action of clicking the back button and then perform the specified operations. This topic introduces how to listen for the mini program back press event by implementing the specific interface of IAPMiniProgram SDK.
Procedures
To listen for the mini program back press event, complete the following steps:
Step 1: Implement GriverBackPressedPointEvent
Implement the GriverBackPressedPointEvent interface and write your business logic in the handleBackPressed
method. Refer to the following sample on how to implement the interface.
public class DemoGriverBackPressedPointEvent implements GriverBackPressedPointEvent {
@Override
public void handleBackPressed(Page page) {
}
@Override
public void onInitialized() {
}
@Override
public void onFinalized() {
}
}
For details about the interface, see GriverBackPressedPointEvent.
Step 2: Register back press event
Refer to the following sample code to call the registerEventHandler API to register the back press event after initializing the SDK.
Griver.registerEventHandler(new GriverEventManifest(DemoGriverBackPressedPointEvent.class.getName(), Arrays.asList(GriverBackPressedPointEvent.class.getName()), App.class));
For more information about the above API, refer to registerEventHandler.
Interface
GriverBackPressedPointEvent
The definition of the GriverBackPressedPointEvent interface is shown in the following codes:
public interface GriverBackPressedPointEvent extends GriverEvent {
void handleBackPressed(Page page);
}
Method
Method Name | Description |
handleBackPressed | The listening event is called when the title bar's back button is clicked. |
Parameters
Name | Type | Length | Description | Required |
page | Page | N/A | The page instance of the mini program. | M |