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 GriverBackPressedPointEvent interface of IAPMiniProgram SDK.
Procedures
To listen for the mini program back press event, complete the following steps:
Step 1: Implement the GriverBackPressedPointEvent interface
Implement the GriverBackPressedPointEvent interface and write your business logic in the handleBackPressed
method. Refer to the following sample on how to implement the interface.
class DemoGriverBackPressedPointEvent : GriverBackPressedPointEvent {
override fun handleBackPressed(page: Page?) {
}
override fun onInitialized() {
}
override fun onFinalized() {
}
}
Step 2: Register the DemoGriverBackPressedPointEvent class
Call the registerEventHandler API to register the back press event after initializing the SDK. For details, see the following GriverBackPressedPointEvent interface.
Griver.registerEventHandler(
GriverEventManifest(
DemoGriverBackPressedPointEvent::class.java.name, Arrays.asList<String>(
GriverBackPressedPointEvent::class.java.name
),
App::class.java
)
)
Structures
GriverBackPressedPointEvent interface
The definition of the GriverBackPressedPointEvent interface is shown in the following codes:
interface GriverBackPressedPointEvent : GriverEvent {
fun handleBackPressed(var1: Page?)
}
Based on the definition, this interface provides the following methods:
Method Name | Description |
The listening event is called when the title bar's back button is clicked. |
handleBackPressed method
Parameter | Data type | Required | Description |
page | Page | Yes | The page instance of the mini program. |