Listen for the page lifecycle event
When opening a page in SDK, similar with the Activity lifecycle, SDK has its own lifecycle. If you want to do some work in the page lifecycle, you can implement the GriverPageHelperEvent that contains the page lifecycle events.
Procedures
To listen for the page lifecycle events, complete the following steps:
Step 1: Implement the GriverPageHelperEvent interface
Implement GriverPageHelperEvent and write code in the required methods according to your business logic. See the following example for how to implement this interface.
class DemoGriverPageHelperEvent : GriverPageHelperEvent {
override fun onPageStarted(page: Page, url: String) {
}
override fun onPageFinished(page: Page, url: String) {
}
override fun onPagePause(page: Page) {
}
override fun onPageResume(page: Page) {
}
override fun onProgressChanged(page: Page, url: String, newProgress: Int) {
}
override fun onPageBacked(page: Page) {
}
override fun onPageExit(page: Page) {
}
override fun onPageDestroy(page: Page) {
}
override fun onInitialized() {
}
override fun onFinalized() {
}
}Step 2: Register the DemoGriverPageHelperEvent class
Call the registerEventHandler API to register the page helper event after initializing the SDK.
Sample code:
Griver.registerEventHandler(
GriverEventManifest(
DemoGriverPageHelperEvent::class.java.name,
Arrays.asList(GriverPageHelperEvent::class.java.name), Page::class.java
)
)Structures
GriverPageHelperEvent interface
The definition of the GriverPageHelperEvent interface is shown in the following code:
interface GriverPageHelperEvent : GriverEvent {
fun onPageStarted(page: Page?, url: String?)
fun onPageFinished(page: Page?, url: String?)
fun onPagePause(page: Page?)
fun onPageResume(page: Page?)
fun onProgressChanged(page: Page?, url: String?, newProgress: Int)
fun onPageBacked(page: Page?)
fun onPageExit(page: Page?)
fun onPageDestroy(page: Page?)
}Based on the definition, this interface provides the following methods:
Method Name | Description |
onPageStarted | The "page started" event is triggered after the WebView finishes loading the page (corresponding to the following It is related to the |
onPageFinished | You can implement the It is related to the |
onPagePause | When page goes to the background, the |
onPageResume | Corresponding to the pause event, the "page resume" event is triggered when the |
onProgressChanged | If you want to know the progress of loading, you can implement the It is related to the |
onPageBacked | If you want to listen for the "page back" event, you can implement the |
onPageExit | If you want to listen for the "page exit" event, you can implement the |
onPageDestroy | If you want to listen for the "page destroy" event , you can implement the |